69 lines
2.5 KiB
C#
69 lines
2.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using LCU.API.Internal.RepoApi.Repos.Models;
|
|
using LCU.API.Internal.RepoApi.Repos.Persistence;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace LCU.API.Internal.RepoApi.Repos.Repositories
|
|
{
|
|
public class ImsAutoFileDataRepository : BaseRepository, IImsAutoFileDataRepository
|
|
{
|
|
public ImsAutoFileDataRepository(AppDbContext context) : base(context)
|
|
{
|
|
}
|
|
|
|
public async Task<IEnumerable<ImsAutoFileData>> ListAllAsync()
|
|
{
|
|
return await _context.ImsAutoFileData.ToListAsync();
|
|
}
|
|
|
|
public async Task AddAsync(ImsAutoFileData assignment)
|
|
{
|
|
await _context.ImsAutoFileData.AddAsync(assignment);
|
|
}
|
|
|
|
public async Task<ImsAutoFileData> FindByIdAsync(string vin, int repoId)
|
|
{
|
|
return await _context.ImsAutoFileData.Where(x => x.VIN == vin && x.RepoId == repoId).FirstOrDefaultAsync();
|
|
}
|
|
|
|
public async Task<ImsAutoFileData> FindByAuctionAssignmentIdAsync(int auctionAssignmentId)
|
|
{
|
|
return await _context.ImsAutoFileData.Where(x => x.AuctionAssignmentId == auctionAssignmentId)
|
|
.FirstOrDefaultAsync();
|
|
}
|
|
|
|
public async Task<ImsAutoFileData> GetNonConformingImsFileRecord(string vin, string auctionCustomerNo)
|
|
{
|
|
ImsAutoFileData imsAutoFile = null;
|
|
|
|
// Allow for vehicle brought back to auction after sale. it happens!
|
|
DateTime withinThirtyDays = DateTime.Now.AddDays(-30);
|
|
imsAutoFile = await _context.ImsAutoFileData.Where(x =>
|
|
(x.VIN.Trim() == vin && x.AuctionCustomerNo == auctionCustomerNo
|
|
&& (x.SoldDate == null || x.SoldDate >= withinThirtyDays))).FirstOrDefaultAsync();
|
|
|
|
return imsAutoFile;
|
|
}
|
|
|
|
public void Update(ImsAutoFileData autoImsAutoFileData)
|
|
{
|
|
_context.ImsAutoFileData.Update(autoImsAutoFileData);
|
|
}
|
|
|
|
public void Remove(ImsAutoFileData autoImsAutoFileData)
|
|
{
|
|
_context.ImsAutoFileData.Remove(autoImsAutoFileData);
|
|
}
|
|
|
|
public async Task<IReadOnlyCollection<ImsAutoFileData>> GetImsSoldRecordsForPeriod(DateTime lowDateTime,
|
|
DateTime highDateTime)
|
|
{
|
|
return await _context.ImsAutoFileData
|
|
.Where(x => x.SoldDate != null && x.SoldDate >= lowDateTime && x.SoldDate <= highDateTime)
|
|
.ToListAsync();
|
|
}
|
|
}
|
|
} |