54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using _0_Framework.Application;
|
|
using _0_Framework.InfraStructure;
|
|
using Company.Domain.FineAgg;
|
|
using CompanyManagment.App.Contracts.Fine;
|
|
|
|
namespace CompanyManagment.EFCore.Repository;
|
|
|
|
public class FineRepository:RepositoryBase<long,Fine>, IFineRepository
|
|
{
|
|
private readonly CompanyContext _companyContext;
|
|
|
|
public FineRepository(CompanyContext companyContext):base(companyContext)
|
|
{
|
|
_companyContext = companyContext;
|
|
}
|
|
|
|
public List<FineSearchViewModel> GetSearchList(FineSearchViewModel searchModel)
|
|
{
|
|
var query = _companyContext.Fines.Where(x => x.WorkshopId == searchModel.WorkshopId);
|
|
|
|
if (searchModel.EmployeeId != 0)
|
|
query = query.Where(x => x.EmployeeId == searchModel.EmployeeId);
|
|
|
|
return query.Select(x => new FineSearchViewModel()
|
|
{
|
|
Id = x.id,
|
|
WorkshopId = x.WorkshopId,
|
|
EmployeeId = x.EmployeeId,
|
|
EmployeeFullName = _companyContext.Employees.FirstOrDefault(e => e.id == x.EmployeeId).FullName,
|
|
PersonnelCode = _companyContext.PersonnelCodeSet.FirstOrDefault(p => p.EmployeeId == x.EmployeeId).PersonnelCode.ToString(),
|
|
Title = x.Title,
|
|
Amount = x.Amount.ToMoney(),
|
|
FineDate = x.FineDate.ToFarsi(),
|
|
IsActive = x.IsActive,
|
|
CreationDate = x.CreationDate
|
|
}).OrderByDescending(x => x.CreationDate).Skip(searchModel.PageIndex).Take(30).ToList();
|
|
}
|
|
|
|
public EditFineViewModel GetDetails(long id)
|
|
{
|
|
return _companyContext.Fines.Select(x => new EditFineViewModel()
|
|
{
|
|
Id = x.id,
|
|
WorkshopId = x.WorkshopId,
|
|
EmployeeId = x.EmployeeId,
|
|
Title = x.Title,
|
|
Amount = x.Amount.ToMoney(),
|
|
IsActive = x.IsActive,
|
|
FineDate = x.FineDate.ToFarsi(),
|
|
}).FirstOrDefault(x => x.Id == id);
|
|
}
|
|
} |