Files
Backend-Api/CompanyManagment.EFCore/Repository/RollCallEmployeeStatusRepository.cs
2024-10-05 19:27:04 +03:30

53 lines
1.6 KiB
C#

using _0_Framework.Application;
using _0_Framework.InfraStructure;
using Company.Domain.RollCallEmployeeStatusAgg;
using CompanyManagment.App.Contracts.RollCallEmployeeStatus;
using System;
using System.Collections.Generic;
using System.Linq;
using CompanyManagment.App.Contracts.RollCallEmployee;
namespace CompanyManagment.EFCore.Repository
{
public class RollCallEmployeeStatusRepository : RepositoryBase<long, RollCallEmployeeStatus>, IRollCallEmployeeStatusRepository
{
private readonly CompanyContext _context;
public RollCallEmployeeStatusRepository(CompanyContext context) : base(context)
{
_context = context;
}
#region Pooya
public List<RollCallEmployeeStatusViewModel> GetAll()
{
return _context.RollCallEmployeesStatus.Select(x => new RollCallEmployeeStatusViewModel()
{
StartDate = x.StartDate.ToFarsi(),
EndDate = x.EndDate.ToFarsi(),
Id = x.id
}).ToList();
}
public void AdjustRollCallStatusEndDates(List<AdjustRollCallEmployeesWithEmployeeLeftWork> command)
{
var statusIds = command.Select(x => x.RollCallStatusId);
var finalList = _context.RollCallEmployeesStatus.Where(x => statusIds.Contains(x.id)).AsEnumerable();
finalList.Where(x => command.Any(y => !y.LeaveDate.IsDateUndefined() && y.LeaveDate < x.EndDate)).ToList().ForEach(
z =>
{
var cmd = command.FirstOrDefault(y => y.RollCallStatusId == z.id);
if (cmd!.LeaveDate >= z.StartDate)
z.Edit(z.StartDate, cmd!.LeaveDate);
}
);
_context.SaveChanges();
}
#endregion
}
}