Esempio n. 1
0
        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);
        }