feat: add method to remove roll call employee statuses and update handling of left work dates

This commit is contained in:
2025-10-29 18:43:23 +03:30
parent 2a9d9574e3
commit 470651cb76
4 changed files with 249 additions and 145 deletions

View File

@@ -26,5 +26,6 @@ namespace Company.Domain.RollCallEmployeeStatusAgg
List<RollCallEmployeeStatusViewModel> GetActiveByWorkshopIdInDate(long workshopId, DateTime startDateGr, DateTime endDateGr);
List<RollCallEmployeeStatusViewModel> GetByWorkshopIdInDates(long workshopId, DateTime start, DateTime end);
bool IsActiveInPeriod(long employeeId, long workshopId, DateTime startDate, DateTime endDate);
void RemoveRange(IEnumerable<RollCallEmployeeStatus> rollCallEmployeeStatusList);
}
}

View File

@@ -36,7 +36,8 @@ public class LeftWorkApplication : ILeftWorkApplication
public LeftWorkApplication(ILeftWorkRepository leftWorkRepository, IContractRepository contractRepository,
IContractApplication contractApplication, IWorkingHoursApplication workingHoursApplication,
IWorkingHoursItemsApplication workingHoursItemsApplication, IEmployeeRepository employeeRepository,
IWorkshopRepository workshopRepository, IRollCallEmployeeStatusRepository rollCallEmployeeStatusRepository, IRollCallEmployeeRepository rollCallEmployeeRepository)
IWorkshopRepository workshopRepository, IRollCallEmployeeStatusRepository rollCallEmployeeStatusRepository,
IRollCallEmployeeRepository rollCallEmployeeRepository)
{
_leftWorkRepository = leftWorkRepository;
_contractRepository = contractRepository;
@@ -51,7 +52,6 @@ public class LeftWorkApplication : ILeftWorkApplication
public OperationResult Create(CreateLeftWork command)
{
// var Contracts = _contractRepository.Search(new ContractSearchModel()
// {
// EmployeeId = command.EmployeeId,
@@ -70,7 +70,6 @@ public class LeftWorkApplication : ILeftWorkApplication
var start = command.StartWorkDate.ToGeorgianDateTime();
//if (_leftWorkRepository.Exists(x =>
// x.StartWorkDate > start && x.EmployeeId == command.EmployeeId && x.WorkshopId == command.WorkshopId))
// return operation.Failed("تاریخ وارد شده کوچکتر از سابقه شروع به کار قبلی است");
@@ -116,10 +115,11 @@ public class LeftWorkApplication : ILeftWorkApplication
var workshopName = workshop.WorkshopFullName;
var leftWork = new LeftWork(left, start, command.WorkshopId,
command.EmployeeId, employeeFullName, workshopName, command.JobId, command.IncludeStatus,
command.AddBonusesPay, command.AddYearsPay, command.AddLeavePay,workshop.ComputeOptions,workshop.BonusesOptions);
command.AddBonusesPay, command.AddYearsPay, command.AddLeavePay, workshop.ComputeOptions,
workshop.BonusesOptions);
_leftWorkRepository.Create(leftWork);
_leftWorkRepository.SaveChanges();
IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(command.EmployeeId);
IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(command.EmployeeId, command.WorkshopId);
return operation.Succcedded();
}
@@ -193,7 +193,7 @@ public class LeftWorkApplication : ILeftWorkApplication
command.EmployeeId, command.JobId, command.IncludeStatus, command.AddBonusesPay, command.AddYearsPay,
command.AddLeavePay);
_leftWorkRepository.SaveChanges();
IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(command.EmployeeId);
IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(command.EmployeeId, command.WorkshopId);
return operation.Succcedded();
}
@@ -214,12 +214,10 @@ public class LeftWorkApplication : ILeftWorkApplication
public List<LeftWorkViewModel> SearchCreateContract(LeftWorkSearchModel searchModel)
{
return _leftWorkRepository.SearchCreateContract(searchModel);
}
public async Task<List<LeftWorkViewModel>> searchAsync(LeftWorkSearchModel searchModel)
{
var res = search(searchModel);
@@ -228,7 +226,6 @@ public class LeftWorkApplication : ILeftWorkApplication
public string GetBeforeDate(string date)
{
var persianBefore = "";
var year = Convert.ToInt32(date.Substring(0, 4));
var month = Convert.ToInt32(date.Substring(5, 2));
@@ -255,10 +252,8 @@ public class LeftWorkApplication : ILeftWorkApplication
}
public void LeftWorkExtension(long contractId, string CStart, string CEnd)
{
var step1 = _contractApplication.GetDetails(contractId);
var step2 = _workingHoursApplication.GetByContractId(contractId);
var step3 = _workingHoursItemsApplication.GetWorkingHoursItems();
@@ -380,13 +375,11 @@ public class LeftWorkApplication : ILeftWorkApplication
ContarctStart = CStart,
ContractEnd = CEnd,
GetWorkDateHide = step1.GetWorkDate,
};
var step5 = _contractApplication.MandatoryHours(computing);
string workingDays = string.Empty;
if (step5.NumberOfWorkingDays == "0")
{
workingDays = step5.ComplexNumberOfWorkingDays;
}
else
@@ -477,8 +470,6 @@ public class LeftWorkApplication : ILeftWorkApplication
OverTimeWorkM = step5.OverTimeWorkM == "0" ? "" : step5.OverTimeWorkM,
OverNightWorkH = step5.OverNightWorkH == "0" ? "" : step5.OverNightWorkH,
OverNightWorkM = step5.OverNightWorkM == "0" ? "" : step5.OverNightWorkM,
};
var resss = _contractApplication.Create(createNew);
}
@@ -529,7 +520,9 @@ public class LeftWorkApplication : ILeftWorkApplication
item.LeftWorkDate = string.IsNullOrWhiteSpace(item.LeftWorkDate) ? "1500/01/01" : item.LeftWorkDate;
var left = item.LeftWorkDate.ToGeorgianDateTime();
var start = item.StartWorkDate.ToGeorgianDateTime();
if (_leftWorkRepository.Exists(x => x.StartWorkDate > start && left == null && x.EmployeeId == informationLeftwork.EmployeeId && x.WorkshopId == informationLeftwork.WorkshopId && x.id!=item.Id))
if (_leftWorkRepository.Exists(x =>
x.StartWorkDate > start && left == null && x.EmployeeId == informationLeftwork.EmployeeId &&
x.WorkshopId == informationLeftwork.WorkshopId && x.id != item.Id))
return operation.Failed("وارد کردن تاریخ پایان کار اجباری است ");
if (_leftWorkRepository.Exists(x =>
x.StartWorkDate == start && x.EmployeeId == informationLeftwork.EmployeeId &&
@@ -540,17 +533,23 @@ public class LeftWorkApplication : ILeftWorkApplication
x.EmployeeId == informationLeftwork.EmployeeId &&
x.WorkshopId == informationLeftwork.WorkshopId && x.id != item.Id))
return operation.Failed("شروع به کار قبلی این شخص ترک کار ندارد ");
if (_leftWorkRepository.Exists(x => x.StartWorkDate <= start && x.LeftWorkDate < left && x.LeftWorkDate >= start && x.EmployeeId == informationLeftwork.EmployeeId && x.WorkshopId == informationLeftwork.WorkshopId && x.id != item.Id))
if (_leftWorkRepository.Exists(x =>
x.StartWorkDate <= start && x.LeftWorkDate < left && x.LeftWorkDate >= start &&
x.EmployeeId == informationLeftwork.EmployeeId &&
x.WorkshopId == informationLeftwork.WorkshopId && x.id != item.Id))
return operation.Failed("تاریخ وارد شده در بازه زمانی سابقه ترک کار قبلی است");
}
}
operation = _leftWorkRepository.CreateLeftWork(informationLeftwork);
if (informationLeftwork != null && operation.IsSuccedded) IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(informationLeftwork.EmployeeId);
if (informationLeftwork != null && operation.IsSuccedded)
IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(informationLeftwork.EmployeeId,
informationLeftwork.WorkshopId);
return operation;
}
public OperationResult CreateLeftWorkByLeftWorkGroups(string employeeFullName, long commandEmployeeId, List<PersonnelCodeViewModel> commandPersonnelCode, List<LeftWorkGroup> leftWorkGroups)
public OperationResult CreateLeftWorkByLeftWorkGroups(string employeeFullName, long commandEmployeeId,
List<PersonnelCodeViewModel> commandPersonnelCode, List<LeftWorkGroup> leftWorkGroups)
{
var operation = new OperationResult();
@@ -560,7 +559,9 @@ public class LeftWorkApplication : ILeftWorkApplication
{
foreach (var item2 in item.LeftWorkViewModels)
{
item2.LeftWorkDate = string.IsNullOrWhiteSpace(item2.LeftWorkDate) ? "1500/01/01" : item2.LeftWorkDate;
item2.LeftWorkDate = string.IsNullOrWhiteSpace(item2.LeftWorkDate)
? "1500/01/01"
: item2.LeftWorkDate;
var left = item2.LeftWorkDate.ToGeorgianDateTime();
var start = item2.StartWorkDate.ToGeorgianDateTime();
if (_leftWorkRepository.Exists(x =>
@@ -586,14 +587,16 @@ public class LeftWorkApplication : ILeftWorkApplication
}
}
operation = _leftWorkRepository.CreateLeftWorkByLeftWorkGroups(employeeFullName, commandEmployeeId, commandPersonnelCode, leftWorkGroups);
if (operation.IsSuccedded) IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(commandEmployeeId);
operation = _leftWorkRepository.CreateLeftWorkByLeftWorkGroups(employeeFullName, commandEmployeeId,
commandPersonnelCode, leftWorkGroups);
if (operation.IsSuccedded)
IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(commandEmployeeId);
return operation;
}
public OperationResult CheckDeleteLeftWork(long workshopId, long employeeId, string date, int type)
{
return _leftWorkRepository.CheckDeleteLeftWork( workshopId, employeeId, date.ToGeorgianDateTime(),type);
return _leftWorkRepository.CheckDeleteLeftWork(workshopId, employeeId, date.ToGeorgianDateTime(), type);
}
public OperationResult CheckEditLeftWork(long workshopId, long employeeId, string date, int type)
@@ -607,11 +610,13 @@ public class LeftWorkApplication : ILeftWorkApplication
}
#region Pooya
//این متد ترک کار های کارمند را با فعالیت حضور غیاب یکپارچه می کند
private void IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(long employeeId)
{
//get last leftworks for employee in all workshops
var leftWorks = _leftWorkRepository.search(new LeftWorkSearchModel() { EmployeeId = employeeId }).GroupBy(x => x.WorkshopId).Select(x =>
var leftWorks = _leftWorkRepository.search(new LeftWorkSearchModel() { EmployeeId = employeeId })
.GroupBy(x => x.WorkshopId).Select(x =>
{
var leftWork = x.MaxBy(y => y.StartWorkDateGr);
return new LeftWorkViewModel()
@@ -632,17 +637,90 @@ public class LeftWorkApplication : ILeftWorkApplication
x.WorkshopId,
x.EmployeeId,
y.LeftWorkDateGr,
Status = x.Statuses.OrderByDescending(z => z.StartDate).FirstOrDefault(z => z.StartDateGr.Date < y.LeftWorkDateGr && z.EndDateGr.Date > y.LeftWorkDateGr)
Status = x.Statuses.OrderByDescending(z => z.StartDate).FirstOrDefault(z =>
z.StartDateGr.Date < y.LeftWorkDateGr && z.EndDateGr.Date > y.LeftWorkDateGr)
});
//shaping up the list to send as parameter to repository
var newRollCallRecords = joinedList.Where(x => x.Status != null).Select(x => new AdjustRollCallEmployeesWithEmployeeLeftWork()
var newRollCallRecords = joinedList.Where(x => x.Status != null).Select(x =>
new AdjustRollCallEmployeesWithEmployeeLeftWork()
{
LeaveDate = x.LeftWorkDateGr,
RollCallStatusId = x.Status.Id
}).ToList();
if(newRollCallRecords.Count > 0)
if (newRollCallRecords.Count > 0)
_rollCallEmployeeStatusRepository.AdjustRollCallStatusEndDates(newRollCallRecords);
foreach (var rollCallEmployeeViewModel in rollCallsEmployee)
{
var maxLeftWork = leftWorks.FirstOrDefault(x => x.WorkshopId == rollCallEmployeeViewModel.WorkshopId);
if (maxLeftWork == null)
{
continue;
}
var employeeStatus = _rollCallEmployeeRepository.GetBy(rollCallEmployeeViewModel.EmployeeId,
rollCallEmployeeViewModel.WorkshopId);
var rollCallEmployeeStatusList = employeeStatus.EmployeesStatus
.Where(x => x.StartDate >= maxLeftWork.LeftWorkDateGr).ToList();
if (rollCallEmployeeStatusList.Any())
{
_rollCallEmployeeStatusRepository.RemoveRange(rollCallEmployeeStatusList);
_rollCallEmployeeStatusRepository.SaveChanges();
}
}
}
private void IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(long employeeId, long workshopId)
{
//get last leftworks for employee in all workshops
var leftWorks = _leftWorkRepository.search(new LeftWorkSearchModel()
{ EmployeeId = employeeId, WorkshopId = workshopId })
.Select(x => new LeftWorkViewModel()
{
EmployeeId = employeeId,
WorkshopId = x.WorkshopId,
LeftWorkDateGr = x.LeftWorkDateGr.Date.AddDays(-1),
StartWorkDateGr = x.StartWorkDateGr
}).ToList();
var maxLeftWork = leftWorks.MaxBy(y => y.StartWorkDateGr);
//get rollCallEmployee associated with those leftworks which have a higher end date than leftworkDate
var rollCallsEmployee = _rollCallEmployeeRepository.GetBy(employeeId, workshopId);
// var joinedList = rollCallsEmployee.Join(leftWorks, x => x.WorkshopId, y => y.WorkshopId, (x, y) => new
// {
// x.WorkshopId,
// x.EmployeeId,
// y.LeftWorkDateGr,
// Status = x.Statuses.OrderByDescending(z => z.StartDate).FirstOrDefault(z => z.StartDateGr.Date < y.LeftWorkDateGr && z.EndDateGr.Date > y.LeftWorkDateGr)
// });
var status = rollCallsEmployee.EmployeesStatus.OrderByDescending(z => z.StartDate)
.FirstOrDefault(rollCallEmployeeStatus => rollCallEmployeeStatus.StartDate.Date < maxLeftWork.LeftWorkDateGr
&& rollCallEmployeeStatus.EndDate.Date >
maxLeftWork.LeftWorkDateGr);
if (status != null)
{
var adjust = new AdjustRollCallEmployeesWithEmployeeLeftWork()
{
LeaveDate = maxLeftWork.LeftWorkDateGr,
RollCallStatusId = status.id
};
_rollCallEmployeeStatusRepository.AdjustRollCallStatusEndDates([adjust]);
}
var rollCallEmployeeStatusList = rollCallsEmployee.EmployeesStatus
.Where(x => x.StartDate >= maxLeftWork.LeftWorkDateGr).ToList();
if (rollCallEmployeeStatusList.Any())
{
_rollCallEmployeeStatusRepository.RemoveRange(rollCallEmployeeStatusList);
_rollCallEmployeeStatusRepository.SaveChanges();
}
}
#endregion

View File

@@ -38,7 +38,11 @@ public class LeftWorkTempApplication : ILeftWorkTempApplication
private readonly IRollCallEmployeeStatusRepository _rollCallEmployeeStatusRepository;
public LeftWorkTempApplication(ILeftWorkTempRepository leftWorkTempRepository, ILeftWorkRepository leftWorkRepository, IWorkshopRepository workshopRepository, IEmployeeRepository employeeRepository, IJobRepository jobRepository, ICheckoutRepository checkoutRepository, IContractRepository contractRepository, IRollCallEmployeeStatusRepository rollCallEmployeeStatusRepository, IRollCallEmployeeRepository rollCallEmployeeRepository)
public LeftWorkTempApplication(ILeftWorkTempRepository leftWorkTempRepository,
ILeftWorkRepository leftWorkRepository, IWorkshopRepository workshopRepository,
IEmployeeRepository employeeRepository, IJobRepository jobRepository, ICheckoutRepository checkoutRepository,
IContractRepository contractRepository, IRollCallEmployeeStatusRepository rollCallEmployeeStatusRepository,
IRollCallEmployeeRepository rollCallEmployeeRepository)
{
_leftWorkTempRepository = leftWorkTempRepository;
_leftWorkRepository = leftWorkRepository;
@@ -59,7 +63,7 @@ public class LeftWorkTempApplication : ILeftWorkTempApplication
{
#region Validation
if (_leftWorkTempRepository.Exists(x=>x.WorkshopId == command.WorkshopId && x.EmployeeId == employeeId))
if (_leftWorkTempRepository.Exists(x => x.WorkshopId == command.WorkshopId && x.EmployeeId == employeeId))
{
return op.Failed("برای پرسنل وارد شده قبلا درخواست ترک کار ثبت کرده اید");
}
@@ -68,6 +72,7 @@ public class LeftWorkTempApplication : ILeftWorkTempApplication
{
return op.Failed("تاریخ شروع به کار وارد شده نامعتبر است");
}
if (command.LastDayStanding.TryToGeorgianDateTime(out var lastDayStandingDateGr) == false)
{
return op.Failed("تاریخ شروع به کار وارد شده نامعتبر است");
@@ -101,7 +106,6 @@ public class LeftWorkTempApplication : ILeftWorkTempApplication
}
//if (leftWork.StartWorkDate >= leftWorkDateGr)
//{
// return op.Failed("ترک کار نمیتواند کوچک تر یا مساوی شروع به کار باشد");
@@ -121,10 +125,10 @@ public class LeftWorkTempApplication : ILeftWorkTempApplication
// return op.Failed("این پرسنل در تاریخ ترک کار وارد شده دارای قرارداد میباشد");
//}
#endregion
var leftWorkTemp = LeftWorkTemp.CreateLeftWork(leftWork.id, leftWork.StartWorkDate, leftWorkDateGr, lastDayStandingDateGr,
var leftWorkTemp = LeftWorkTemp.CreateLeftWork(leftWork.id, leftWork.StartWorkDate, leftWorkDateGr,
lastDayStandingDateGr,
command.WorkshopId, employeeId, leftWork.JobId);
await _leftWorkTempRepository.CreateAsync(leftWorkTemp);
@@ -154,7 +158,9 @@ public class LeftWorkTempApplication : ILeftWorkTempApplication
return op.Failed("اطلاعات وارد شده نامعتبر است");
}
if (_leftWorkRepository.Exists(x => x.WorkshopId == leftWorkTemp.WorkshopId && x.EmployeeId == leftWorkTemp.EmployeeId && x.LeftWorkDate >= startDateGr))
if (_leftWorkRepository.Exists(x =>
x.WorkshopId == leftWorkTemp.WorkshopId && x.EmployeeId == leftWorkTemp.EmployeeId &&
x.LeftWorkDate >= startDateGr))
{
return op.Failed("شروع به کار وارد شده با ترک کار های قبلی تداخل دارد");
}
@@ -183,8 +189,8 @@ public class LeftWorkTempApplication : ILeftWorkTempApplication
{
var startWork = newLeftWork.StartWorkDate;
rollCallStatus.Edit(startWork, rollCallStatus.EndDate);
}
await _leftWorkRepository.SaveChangesAsync();
await _leftWorkTempRepository.SaveChangesAsync();
@@ -237,9 +243,12 @@ public class LeftWorkTempApplication : ILeftWorkTempApplication
x.WorkshopId == leftWorkTemp.WorkshopId &&
x.ContractStart <= lastDayStandingGr && x.ContractEnd >= lastDayStandingGr))
{
return op.Failed("این پرسنل در تاریخ ترک کار وارد شده دارای فیش حقوقی میباشد. ابتدا فیش حقوقی پرسنل را حذف کنید ");
return op.Failed(
"این پرسنل در تاریخ ترک کار وارد شده دارای فیش حقوقی میباشد. ابتدا فیش حقوقی پرسنل را حذف کنید ");
}
var transaction = await _rollCallEmployeeStatusRepository.BeginTransactionAsync();
leftWork.Edit(leftWorkDateGr, leftWork.StartWorkDate, leftWork.WorkshopId, leftWork.EmployeeId, leftWork.JobId,
leftWork.IncludeStatus, leftWork.AddBonusesPay, leftWork.AddYearsPay, leftWork.AddLeavePay);
@@ -247,8 +256,9 @@ public class LeftWorkTempApplication : ILeftWorkTempApplication
await _leftWorkRepository.SaveChangesAsync();
await _leftWorkTempRepository.SaveChangesAsync();
IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(leftWork.EmployeeId);
IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(leftWork.EmployeeId, leftWork.WorkshopId);
await transaction.CommitAsync();
return op.Succcedded();
}
@@ -260,44 +270,58 @@ public class LeftWorkTempApplication : ILeftWorkTempApplication
public List<LeftWorkTempViewModel> GetLeftWorksByWorkshopId(long workshopId)
{
return _leftWorkTempRepository.GetLeftWorksByWorkshopId(workshopId);
}
//این متد ترک کار های کارمند را با فعالیت حضور غیاب یکپارچه می کند
private void IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(long employeeId)
private void IfEmployeeHasNewLeftWorkDateAddEndDateToRollCallStatus(long employeeId, long workshopId)
{
//get last leftworks for employee in all workshops
var leftWorks = _leftWorkRepository.search(new LeftWorkSearchModel() { EmployeeId = employeeId }).GroupBy(x => x.WorkshopId).Select(x =>
{
var leftWork = x.MaxBy(y => y.StartWorkDateGr);
return new LeftWorkViewModel()
var leftWorks = _leftWorkRepository.search(new LeftWorkSearchModel()
{ EmployeeId = employeeId, WorkshopId = workshopId })
.Select(x => new LeftWorkViewModel()
{
EmployeeId = employeeId,
WorkshopId = x.Key,
LeftWorkDateGr = leftWork.LeftWorkDateGr.Date.AddDays(-1),
StartWorkDateGr = leftWork.StartWorkDateGr
};
WorkshopId = x.WorkshopId,
LeftWorkDateGr = x.LeftWorkDateGr.Date.AddDays(-1),
StartWorkDateGr = x.StartWorkDateGr
}).ToList();
var maxLeftWork = leftWorks.MaxBy(y => y.StartWorkDateGr);
//get rollCallEmployee associated with those leftworks which have a higher end date than leftworkDate
var rollCallsEmployee = _rollCallEmployeeRepository.GetByEmployeeIdWithStatuses(employeeId)
.Where(x => leftWorks.Any(y => y.WorkshopId == x.WorkshopId)).ToList();
var rollCallsEmployee = _rollCallEmployeeRepository.GetBy(employeeId, workshopId);
var joinedList = rollCallsEmployee.Join(leftWorks, x => x.WorkshopId, y => y.WorkshopId, (x, y) => new
{
x.WorkshopId,
x.EmployeeId,
y.LeftWorkDateGr,
Status = x.Statuses.OrderByDescending(z => z.StartDate).FirstOrDefault(z => z.StartDateGr.Date < y.LeftWorkDateGr && z.EndDateGr.Date > y.LeftWorkDateGr)
});
// var joinedList = rollCallsEmployee.Join(leftWorks, x => x.WorkshopId, y => y.WorkshopId, (x, y) => new
// {
// x.WorkshopId,
// x.EmployeeId,
// y.LeftWorkDateGr,
// Status = x.Statuses.OrderByDescending(z => z.StartDate).FirstOrDefault(z => z.StartDateGr.Date < y.LeftWorkDateGr && z.EndDateGr.Date > y.LeftWorkDateGr)
// });
//shaping up the list to send as parameter to repository
var newRollCallRecords = joinedList.Where(x => x.Status != null).Select(x => new AdjustRollCallEmployeesWithEmployeeLeftWork()
var status = rollCallsEmployee.EmployeesStatus.OrderByDescending(z => z.StartDate)
.FirstOrDefault(rollCallEmployeeStatus => rollCallEmployeeStatus.StartDate.Date < maxLeftWork.LeftWorkDateGr
&& rollCallEmployeeStatus.EndDate.Date >
maxLeftWork.LeftWorkDateGr);
if (status != null)
{
LeaveDate = x.LeftWorkDateGr,
RollCallStatusId = x.Status.Id
}).ToList();
if (newRollCallRecords.Count > 0)
_rollCallEmployeeStatusRepository.AdjustRollCallStatusEndDates(newRollCallRecords);
var adjust = new AdjustRollCallEmployeesWithEmployeeLeftWork()
{
LeaveDate = maxLeftWork.LeftWorkDateGr,
RollCallStatusId = status.id
};
_rollCallEmployeeStatusRepository.AdjustRollCallStatusEndDates([adjust]);
}
var rollCallEmployeeStatusList = rollCallsEmployee.EmployeesStatus
.Where(x => x.StartDate >= maxLeftWork.LeftWorkDateGr).ToList();
if (rollCallEmployeeStatusList.Any())
{
_rollCallEmployeeStatusRepository.RemoveRange(rollCallEmployeeStatusList);
_rollCallEmployeeStatusRepository.SaveChanges();
}
}
}

View File

@@ -478,7 +478,8 @@ public class RollCallEmployeeRepository : RepositoryBase<long, RollCallEmployee>
public RollCallEmployee GetBy(long employeeId, long workshopId)
{
return _context.RollCallEmployees.Include(x => x.EmployeesStatus).FirstOrDefault(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId);
return _context.RollCallEmployees.Include(x => x.EmployeesStatus)
.FirstOrDefault(x => x.EmployeeId == employeeId && x.WorkshopId == workshopId);
}
#endregion