Files
monorepo/LCU.API.Collections.RepoApi-old/LCU.API.Collections.RepoApi/Domain/Extensions/RepoAccountExtensions.cs
T
2026-04-20 14:47:24 -05:00

73 lines
2.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using LCU.API.Collections.CollectionsApiLib.Models;
using LCU.Shared.Collections.RepoApiLib.Models;
namespace LCU.API.Collections.RepoApi.Domain.Extensions
{
public static class RepoAccountExtensions
{
public static bool HasAnyCollateral(this RepoAccount repoAccount)
{
return repoAccount?.Collaterals != null && repoAccount.Collaterals.Any();
}
public static IReadOnlyCollection<string> GetCollateralVinList(this RepoAccount repoAccount)
{
if (repoAccount?.Collaterals != null && repoAccount.Collaterals.Any())
{
return repoAccount.Collaterals.Select(x => x.Vin?.Trim().ToUpper()).ToList();
}
return new List<string>();
}
public static IReadOnlyCollection<int> GetUniqueAuctionAssignmentIds(this RepoAccount repoAccount)
{
var aaList = new List<int>();
if (repoAccount?.Collaterals == null || !repoAccount.Collaterals.Any()) return aaList;
foreach (var collateral in repoAccount.Collaterals)
{
if (collateral.AuctionAssignmentToCollaterals?.Any() != true) continue;
foreach (var toCollateral in collateral.AuctionAssignmentToCollaterals)
{
aaList.Add(toCollateral.AuctionAssignmentId);
}
}
return aaList;
}
public static int GetDaysInStatus(this RepoAccount repoAccount, string status)
{
if (repoAccount?.RepoStatusChanges == null || !repoAccount.RepoStatusChanges.Any())
{
return -1;
}
var lastStatus = repoAccount.RepoStatusChanges.LastOrDefault(x => x.StatusTo == status);
if (lastStatus != null)
{
return (DateTime.Now - lastStatus.ChangedDate).Days;
}
return -1;
}
public static bool IsCurrentlySkipClaim(this RepoAccount updatedRepoAccount)
{
foreach (var collateral in updatedRepoAccount.Collaterals)
{
if (collateral.RepoCompanySelections == null || !collateral.RepoCompanySelections.Any()) continue;
if (collateral.RepoCompanySelections?.OrderByDescending(x => x.DateTimeCreated).First().RepoType ==
RepoType.Skip)
{
return true;
}
}
return false;
}
}
}