71 lines
2.1 KiB
C#
71 lines
2.1 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();
|
|
|
|
}
|
|
/// <summary>
|
|
/// برای تغییر بازه فعالبت هنگام ترک کار
|
|
/// </summary>
|
|
public void AdjustRollCallStatusEndDates(List<AdjustRollCallEmployeesWithEmployeeLeftWork> command)
|
|
{
|
|
//status ids
|
|
var statusIds = command.Select(x => x.RollCallStatusId);
|
|
|
|
//fetch by ids
|
|
var finalList = _context.RollCallEmployeesStatus.Where(x => statusIds.Contains(x.id)).AsEnumerable();
|
|
|
|
|
|
//get the statuses which have higher end date than employee's leftwork
|
|
finalList.Where(x => command.Any(y => !y.LeaveDate.IsDateUndefined() && y.LeaveDate.Date < x.EndDate.Date)).ToList().ForEach(
|
|
z =>
|
|
{
|
|
var cmd = command.FirstOrDefault(y => y.RollCallStatusId == z.id);
|
|
|
|
if (cmd!.LeaveDate.Date > z.StartDate.Date)
|
|
{
|
|
z.Edit(z.StartDate, cmd!.LeaveDate.Date);
|
|
}
|
|
}
|
|
);
|
|
|
|
_context.SaveChanges();
|
|
}
|
|
|
|
|
|
public RollCallEmployeeStatus GetByRollCallEmployeeIdAndDate(long rollCallEmployeeId, DateTime date)
|
|
{
|
|
return _context.RollCallEmployeesStatus.FirstOrDefault(x => x.RollCallEmployeeId == rollCallEmployeeId && x.StartDate.Date <= date.Date && x.EndDate.Date >= date.Date);
|
|
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|