This commit is contained in:
Zeeshaun
2026-03-17 08:54:34 -05:00
parent 64856c640e
commit cdcba54aa4
330 changed files with 54110 additions and 0 deletions
@@ -0,0 +1,41 @@
using ReserveManagementSystemLib.Models;
using ReserveManagementSystemLib.Persistence;
namespace ReserveManagementSystemLib.Repositories
{
public class AuditHistoryRepository: BaseRepository, IAuditHistoryRepository
{
public AuditHistoryRepository(AppDbContext context) : base(context) { }
public IQueryable<AuditHistory> GetAll()
{
return _context.AuditHistories;
}
public async Task<AuditHistory> FindByIdAsync(int id)
{
return await _context.AuditHistories.FirstOrDefaultAsync(l => l.AuditId == id);
}
public async Task<AuditHistory> AddHistoryAsync(AuditHistory history)
{
try
{
var newAudit = await _context.AuditHistories.AddAsync(history);
await _context.SaveChangesAsync();
return newAudit.Entity;
}
catch (Exception ex)
{
Log.Error(ex, $"Failure to add audit history");
return null;
}
}
public async Task<int> AddHistoriesAsync(List<AuditHistory> histories)
{
await _context.AuditHistories.AddRangeAsync(histories);
return await _context.SaveChangesAsync();
}
}
}
@@ -0,0 +1,14 @@
using ReserveManagementSystemLib.Persistence;
namespace ReserveManagementSystemLib.Repositories
{
public class BaseRepository
{
protected readonly AppDbContext _context;
public BaseRepository(AppDbContext context)
{
_context = context;
}
}
}
@@ -0,0 +1,47 @@
using ReserveManagementSystemLib.Models;
using ReserveManagementSystemLib.Persistence;
namespace ReserveManagementSystemLib.Repositories
{
public class DealerRepository : BaseRepository, IDealerRepository
{
public DealerRepository(AppDbContext context) : base(context) { }
public async Task<Dealer> FindByCodeAsync(string code)
{
return await _context.Dealers.FirstOrDefaultAsync(d => d.DealerCode == code);
}
public IQueryable<Dealer> GetAll()
{
return _context.Dealers;
}
public async Task<Dealer> AddDealerAsync(Dealer dealer)
{
try
{
var newDealer = await _context.Dealers.AddAsync(dealer);
await _context.SaveChangesAsync();
return newDealer.Entity;
}
catch (Exception ex)
{
Log.Error(ex, $"Failure to add dealer.");
return null;
}
}
public async Task<int> UpdateDealersAsync(List<Dealer> dealers)
{
_context.Dealers.UpdateRange(dealers);
return await _context.SaveChangesAsync();
}
public async Task<int> AddDealersAsync(List<Dealer> dealers)
{
_context.Dealers.AddRange(dealers);
return await _context.SaveChangesAsync();
}
}
}
@@ -0,0 +1,15 @@
using ReserveManagementSystemLib.Models;
namespace ReserveManagementSystemLib.Repositories
{
public interface IAuditHistoryRepository
{
IQueryable<AuditHistory> GetAll();
Task<AuditHistory> FindByIdAsync(int id);
Task<AuditHistory> AddHistoryAsync(AuditHistory history);
Task<int> AddHistoriesAsync(List<AuditHistory> histories);
}
}
@@ -0,0 +1,17 @@
using ReserveManagementSystemLib.Models;
namespace ReserveManagementSystemLib.Repositories
{
public interface IDealerRepository
{
Task<Dealer> FindByCodeAsync(string dealerCode);
IQueryable<Dealer> GetAll();
Task<Dealer> AddDealerAsync(Dealer dealer);
Task<int> UpdateDealersAsync(List<Dealer> dealers);
Task<int> AddDealersAsync(List<Dealer> dealers);
}
}
@@ -0,0 +1,18 @@
using ReserveManagementSystemLib.Enums;
using ReserveManagementSystemLib.Models;
namespace ReserveManagementSystemLib.Repositories
{
public interface IImportRepository
{
IQueryable<Import> GetAll();
Task<Import> FindByIdAsync(int id);
Task<Import> AddImportAsync(Import import);
Task<Import> UpdateImportAsync(Import import);
IQueryable<Import> GetLastLoanDnaImportByType(ImportType importType);
}
}
@@ -0,0 +1,17 @@
using ReserveManagementSystemLib.Models;
namespace ReserveManagementSystemLib.Repositories
{
public interface ILoanRepository
{
IQueryable<Loan> GetAll();
IQueryable<Loan> GetAllWithoutDealer();
Task<Loan> FindByIdAsync(int id);
Loan Add(Loan loan);
Task UpdateAsync(IEnumerable<Loan> loans);
}
}
@@ -0,0 +1,11 @@
using ReserveManagementSystemLib.Models;
namespace ReserveManagementSystemLib.Repositories
{
public interface ILoanTypeRepository
{
Task<List<LoanType>> GetLoanTypesAsync();
Task<LoanType> GetLoanTypeAsync(string loanTypeId);
}
}
@@ -0,0 +1,9 @@
using ReserveManagementSystemLib.Models;
namespace ReserveManagementSystemLib.Repositories
{
public interface IMinorAccountTypeRepository
{
MinorAccountType GetMinorAccountType(string accountTypeId);
}
}
@@ -0,0 +1,10 @@
using ReserveManagementSystemLib.Models;
namespace ReserveManagementSystemLib.Repositories
{
public interface IVehicleRepository
{
Task<Vehicle> FindByLoanIdAsync(int? loanId);
}
}
@@ -0,0 +1,49 @@
using ReserveManagementSystemLib.Enums;
using ReserveManagementSystemLib.Models;
using ReserveManagementSystemLib.Persistence;
namespace ReserveManagementSystemLib.Repositories
{
public class ImportRepository: BaseRepository, IImportRepository
{
public ImportRepository(AppDbContext context) : base(context) { }
public IQueryable<Import> GetAll()
{
return _context.Imports;
}
public async Task<Import> FindByIdAsync(int id)
{
return await _context.Imports.FirstOrDefaultAsync(l => l.ImportId == id);
}
public async Task<Import> AddImportAsync(Import import)
{
try
{
var newImport = await _context.Imports.AddAsync(import);
await _context.SaveChangesAsync();
return newImport.Entity;
}
catch (Exception ex)
{
Log.Error(ex, $"Failure to add import");
return null;
}
}
public async Task<Import> UpdateImportAsync(Import import)
{
var updatedImport = _context.Imports.Update(import);
await _context.SaveChangesAsync();
return updatedImport.Entity;
}
public IQueryable<Import> GetLastLoanDnaImportByType(ImportType importType)
{
var result = _context.Imports.Where(i => i.ImportType == importType.ToString() && i.Success == true && i.FileName == null).OrderByDescending(i => i.StartDate);
return result;
}
}
}
@@ -0,0 +1,40 @@
using ReserveManagementSystemLib.Models;
using ReserveManagementSystemLib.Persistence;
namespace ReserveManagementSystemLib.Repositories
{
public class LoanRepository : BaseRepository, ILoanRepository
{
public LoanRepository(AppDbContext context) : base(context) { }
public IQueryable<Loan> GetAll()
{
return _context.Loans.Include(d => d.Dealer).Include(lt => lt.LoanType).Include("Vehicle");
}
public IQueryable<Loan> GetAllWithoutDealer()
{
return _context.Loans.Include(lt => lt.LoanType).Include("Vehicle");
}
public async Task<Loan> FindByIdAsync(int id)
{
return await _context.Loans.Where(l => l.LoanId == id).Include(d => d.Dealer).Include(lt => lt.LoanType).Include("Vehicle").FirstOrDefaultAsync();
}
public Loan Add(Loan loan)
{
var result =_context.Loans.Add(loan);
_context.SaveChanges();
return result.Entity;
}
public async Task UpdateAsync(IEnumerable<Loan> loans)
{
_context.Loans.UpdateRange(loans);
await _context.SaveChangesAsync(); //can use this for update and add
}
}
}
@@ -0,0 +1,20 @@
using ReserveManagementSystemLib.Models;
using ReserveManagementSystemLib.Persistence;
namespace ReserveManagementSystemLib.Repositories
{
public class LoanTypeRepository: BaseRepository, ILoanTypeRepository
{
public LoanTypeRepository(AppDbContext context) : base(context) { }
public async Task<List<LoanType>> GetLoanTypesAsync()
{
return await _context.LoanTypes.ToListAsync();
}
public async Task<LoanType> GetLoanTypeAsync(string loanTypeId)
{
return await _context.LoanTypes.FirstOrDefaultAsync(x => x.LoanTypeId == loanTypeId);
}
}
}
@@ -0,0 +1,20 @@
using ReserveManagementSystemLib.Models;
using ReserveManagementSystemLib.Persistence;
namespace ReserveManagementSystemLib.Repositories
{
public class MinorAccountTypeRepository : BaseRepository, IMinorAccountTypeRepository
{
public MinorAccountTypeRepository(AppDbContext context) : base(context) { }
/// <summary>
/// Try to get this to work asynchronously like Loan Types will have to add a get all and then call get by id async
/// </summary>
/// <param name="accountTypeId"></param>
/// <returns></returns>
public MinorAccountType GetMinorAccountType(string accountTypeId)
{
return _context.MinorAccountTypes.FirstOrDefault(x => x.AccountType == accountTypeId);
}
}
}
@@ -0,0 +1,16 @@
using ReserveManagementSystemLib.Models;
using ReserveManagementSystemLib.Persistence;
namespace ReserveManagementSystemLib.Repositories
{
public class VehicleRepository : BaseRepository, IVehicleRepository
{
public VehicleRepository(AppDbContext context) : base(context) { }
public async Task<Vehicle> FindByLoanIdAsync(int? loanId)
{
return await _context.Vehicles.FirstOrDefaultAsync(v => v.LoanId == loanId);
}
}
}