Files
Backend-Api/CompanyManagment.EFCore/Repository/EmployeeChildrenRepository.cs
2024-07-05 21:36:15 +03:30

69 lines
2.0 KiB
C#

using System.Collections.Generic;
using System.Linq;
using _0_Framework.Application;
using _0_Framework.InfraStructure;
using Company.Domain.EmployeeChildrenAgg;
using CompanyManagment.App.Contracts.EmployeeChildren;
namespace CompanyManagment.EFCore.Repository;
public class EmployeeChildrenRepository : RepositoryBase<long, EmployeeChildren>, IEmployeeChildrenRepository
{
private readonly CompanyContext _context;
public EmployeeChildrenRepository(CompanyContext context) : base(context)
{
_context = context;
}
public List<EmployeeChildernViewModel> GetChildren(long employeId)
{
return _context.EmployeeChildrenSet.Select(x => new EmployeeChildernViewModel
{
Id = x.id,
FName = x.FName,
DateOfBirth = x.DateOfBirth.ToFarsi(),
ParentNationalCode = x.ParentNationalCode,
EmployeeId = x.EmployeeId,
IsRemoved = false,
}).Where(x => x.EmployeeId == employeId).ToList();
}
public EditEmployeeChildren GetDetails(long id)
{
return _context.EmployeeChildrenSet.Select(x => new EditEmployeeChildren
{
Id = x.id,
FName = x.FName,
DateOfBirth = x.DateOfBirth.ToFarsi(),
ParentNationalCode = x.ParentNationalCode,
EmployeeId = x.EmployeeId,
})
.FirstOrDefault(x => x.Id == id);
}
public List<EmployeeChildernViewModel> Search(EmployeeChildrenSearchModel searchModel)
{
var query = _context.EmployeeChildrenSet.Select(x => new EmployeeChildernViewModel
{
Id = x.id,
FName = x.FName,
DateOfBirth = x.DateOfBirth.ToFarsi(),
ParentNationalCode = x.ParentNationalCode,
EmployeeId = x.EmployeeId,
});
if (!string.IsNullOrWhiteSpace(searchModel.FName))
query = query.Where(x => x.FName.Contains(searchModel.FName));
return query.OrderByDescending(x => x.Id).ToList();
}
}