Esempio n. 1
0
        public UpdatePlanResponse UpdateLeavesPlan([FromBody] LeavesPlanUpdate leaves, string employeId, NotificationType notificationType, bool force = false)
        {
            var loggedEmploye   = GetLoggedEmploye();
            var targetEmployeId = GetEmployeId(employeId);

            var response = _leaveService.UpdateLeavesPlan(_coverageService, leaves, targetEmployeId, loggedEmploye, force);

            _mailService.SendNotification(notificationType, loggedEmploye, targetEmployeId, response, GetServerLink());

            return(response);
        }
Esempio n. 2
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);
        }