74 lines
2.6 KiB
C#
74 lines
2.6 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using _0_Framework.InfraStructure;
|
|
using Company.Domain.InsuranceAgg;
|
|
using CompanyManagment.App.Contracts.Insurance;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace CompanyManagment.EFCore.Repository;
|
|
|
|
public class InsuranceRepository : RepositoryBase<long, Insurance>, IInsuranceRepository
|
|
{
|
|
private readonly CompanyContext _context;
|
|
public InsuranceRepository(CompanyContext context) : base(context)
|
|
{
|
|
_context = context;
|
|
}
|
|
public InsuranceViewModel GetDetails(long id)
|
|
{
|
|
return _context.Insurances.Where(x => x.id == id).Include(x => x.Workshop).Select(x => new InsuranceViewModel
|
|
{
|
|
Id = x.id,
|
|
Year = x.Year,
|
|
Month = x.Month,
|
|
Address = x.Address,
|
|
EmployerStr = x.EmployerStr,
|
|
WorkShopStr = x.WorkShopStr,
|
|
ListNumber = x.ListNumber,
|
|
WorkShopId = x.WorkShopId
|
|
}).FirstOrDefault();
|
|
}
|
|
|
|
public void Remove(long id)
|
|
{
|
|
var query = _context.Insurances.Where(x => x.id == id).FirstOrDefault();
|
|
Remove(query);
|
|
}
|
|
|
|
public IEnumerable<InsuranceViewModel> Search(InsuranceSearchModel searchModel)
|
|
{
|
|
var query = _context.Insurances.Include(x => x.Workshop).Select(x => new InsuranceViewModel
|
|
{
|
|
Id = x.id,
|
|
Year = x.Year,
|
|
Month = x.Month,
|
|
Address = x.Address,
|
|
EmployerStr = x.EmployerStr,
|
|
WorkShopStr = x.WorkShopStr,
|
|
ListNumber = x.ListNumber,
|
|
WorkShopId = x.WorkShopId,
|
|
Workshop = new App.Contracts.Workshop.WorkshopViewModel
|
|
{
|
|
Id = x.Workshop.id,
|
|
InsuranceCode = x.Workshop.InsuranceCode
|
|
}
|
|
});
|
|
|
|
if (!string.IsNullOrWhiteSpace(searchModel.Address))
|
|
query = query.Where(x => x.Address.Contains(searchModel.Address));
|
|
if (!string.IsNullOrWhiteSpace(searchModel.EmployerStr))
|
|
query = query.Where(x => x.EmployerStr.Contains(searchModel.EmployerStr));
|
|
if (!string.IsNullOrWhiteSpace(searchModel.WorkShopStr))
|
|
query = query.Where(x => x.EmployerStr.Contains(searchModel.WorkShopStr));
|
|
if (searchModel.Year != 0)
|
|
query = query.Where(x => x.Year == searchModel.Year);
|
|
if (searchModel.Month != 0)
|
|
query = query.Where(x => x.Month == searchModel.Month);
|
|
if (searchModel.WorkShopId != 0)
|
|
query = query.Where(x => x.WorkShopId == searchModel.WorkShopId);
|
|
|
|
|
|
return query.OrderByDescending(x => x.Id).ToList();
|
|
}
|
|
|
|
} |