private UpdatePlanResponse AddRejectedLeavesToResponse(ICoverageService coverageService, IList <LeaveDto> leaves, Employe currentEmploye) { var response = new UpdatePlanResponse(); if (leaves?.Count > 0) { var init = leaves.Min(l => l.Date); var end = leaves.Max(l => l.Date); var daysToRemove = coverageService.GetInflexibiltyDays(currentEmploye.Id, init, end).ToList(); daysToRemove = daysToRemove.Where(day => leaves.Any(l => l.Date == day)).ToList(); if (daysToRemove?.Count > 0) { response.RejectedDates = daysToRemove.Select(d => d.ToString(DateIsoFormat)).ToArray(); daysToRemove.ForEach(day => leaves.Remove(leaves.FirstOrDefault(l => l.Date == day))); } } return(response); }
public UpdatePlanResponse UpdateLeavesPlan(ICoverageService coverageService, LeavesPlanUpdate leaves, long employeId, EmployeDto loggedOne, bool force) { Employe currentEmploye = _employeRepository.GetWithArea(employeId); var response = force ? new UpdatePlanResponse() : AddRejectedLeavesToResponse(coverageService, leaves.AddedLeaves, currentEmploye); if (loggedOne.Profile == EmployeProfile.Manager) { _leaveRepository.InsertAll(GetLeavesEntity(leaves.AddedLeaves.Where(l => l.State == LeaveState.Approved).ToList(), currentEmploye, LeaveState.Approved)); _leaveRepository.UpdateAll(GetLeavesEntity(leaves.AddedLeaves.Where(l => l.State == LeaveState.ToAdd).ToList(), currentEmploye, LeaveState.Approved)); _leaveRepository.DeleteAll(GetLeavesEntity(leaves.RemovedLeaves, currentEmploye, LeaveState.Approved)); } else { _leaveRepository.InsertAll(GetLeavesEntity(leaves.AddedLeaves, currentEmploye, LeaveState.ToAdd)); _leaveRepository.DeleteAll(GetLeavesEntity(leaves.RemovedLeaves.Where(l => l.State == LeaveState.ToAdd).ToList(), currentEmploye, LeaveState.ToRemove)); _leaveRepository.UpdateAll(GetLeavesEntity(leaves.RemovedLeaves.Where(l => l.State == LeaveState.Approved).ToList(), currentEmploye, LeaveState.ToRemove)); } SetUpdatedDatesMessage(leaves.AddedLeaves, leaves.RemovedLeaves, response); return(response); }
public LeaveController(ILeaveService leaveService, ICoverageService coverageService, IMailService mailService) { _leaveService = leaveService; _coverageService = coverageService; _mailService = mailService; }
public CoverageController(ICoverageService coverageService) { _coverageService = coverageService; }