50 lines
1.7 KiB
C#
50 lines
1.7 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using _0_Framework.Application;
|
|
using _0_Framework.InfraStructure;
|
|
using Company.Domain.SalaryAidAgg;
|
|
using CompanyManagment.App.Contracts.SalaryAid;
|
|
|
|
namespace CompanyManagment.EFCore.Repository;
|
|
|
|
public class SalaryAidRepository:RepositoryBase<long,SalaryAid>,ISalaryAidRepository
|
|
{
|
|
private readonly CompanyContext _context;
|
|
|
|
public SalaryAidRepository(CompanyContext context):base(context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public List<SalaryAidSearchViewModel> GetSearchList(SalaryAidSearchViewModel searchViewModel)
|
|
{
|
|
var query = _context.SalaryAids.Where(x => x.WorkshopId == searchViewModel.WorkshopId);
|
|
|
|
if (searchViewModel.EmployeeId != 0)
|
|
query = query.Where(x => x.EmployeeId == searchViewModel.EmployeeId);
|
|
|
|
return query.Select(x => new SalaryAidSearchViewModel()
|
|
{
|
|
Id = x.id,
|
|
WorkshopId = x.WorkshopId,
|
|
EmployeeId = x.EmployeeId,
|
|
EmployeeFullName = _context.Employees.FirstOrDefault(e => e.id == x.EmployeeId).FullName,
|
|
PersonnelCode = _context.PersonnelCodeSet.FirstOrDefault(p => p.EmployeeId == x.EmployeeId).PersonnelCode.ToString(),
|
|
Amount = x.Amount.ToMoney(),
|
|
SalaryDateTime = x.SalaryAidDateTime.ToFarsi(),
|
|
CreationDate = x.CreationDate
|
|
}).OrderByDescending(x => x.CreationDate).Skip(searchViewModel.PageIndex).Take(30).ToList();
|
|
}
|
|
|
|
public EditSalaryAidViewModel GetDetails(long id)
|
|
{
|
|
return _context.SalaryAids.Select(x => new EditSalaryAidViewModel()
|
|
{
|
|
Id = x.id,
|
|
WorkshopId = x.WorkshopId,
|
|
EmployeeId = x.EmployeeId,
|
|
Amount = x.Amount.ToMoney(),
|
|
SalaryDateTime = x.SalaryAidDateTime.ToFarsi()
|
|
}).FirstOrDefault(x => x.Id == id);
|
|
}
|
|
} |