コード例 #1
0
 public bool Insert(LeaveRequestVM leaveRequestVM)
 {
     if (string.IsNullOrWhiteSpace(leaveRequestVM.Requester_Id.ToString()))
     {
         return(status);
     }
     else if (string.IsNullOrWhiteSpace(leaveRequestVM.FromDate.ToString()))
     {
         return(status);
     }
     else if (string.IsNullOrWhiteSpace(leaveRequestVM.EndDate.ToString()))
     {
         return(status);
     }
     else if (string.IsNullOrEmpty(leaveRequestVM.Reason.ToString()))
     {
         return(status);
     }
     else if (string.IsNullOrEmpty(leaveRequestVM.Leave_Id.ToString()))
     {
         return(status);
     }
     else
     {
         return(iLeaveRequestRepository.Insert(leaveRequestVM));
     }
 }
コード例 #2
0
 public bool Insert(LeaveRequestVM leaveRequestVM)
 {
     if (string.IsNullOrWhiteSpace(leaveRequestVM.Request_Date.ToString()) ||
         string.IsNullOrWhiteSpace(leaveRequestVM.From_Date.ToString()) ||
         string.IsNullOrWhiteSpace(leaveRequestVM.End_Date.ToString()) ||
         string.IsNullOrWhiteSpace(leaveRequestVM.Employee_Id.ToString()) ||
         string.IsNullOrWhiteSpace(leaveRequestVM.Reason) ||
         string.IsNullOrWhiteSpace(leaveRequestVM.LeaveType_Id.ToString()) ||
         string.IsNullOrWhiteSpace(leaveRequestVM.Status) ||
         string.IsNullOrWhiteSpace(leaveRequestVM.Manager_Id.ToString()))
     {
         return(false);
     }
     else
     {
         return(iLeaveRequestRepository.Insert(leaveRequestVM));
     }
 }
コード例 #3
0
        public OutputBase MakeLeaveRequest(MakeLeaveRequestInput input)
        {
            if (input.LeaveRequest.EmployeeId == 0)
            {
                input.LeaveRequest.EmployeeId = GetCurrentUser().Id;
            }
            var period =
                _leavePeriodRepository.FirstOrDefault(
                    p => input.LeaveRequest.StartDate >= p.StatDate && input.LeaveRequest.EndDate <= p.EndDate);

            if (period == null)
            {
                return new OutputBase {
                           Message = "There is no leave period within the selected date", Success = false
                }
            }
            ;
            var leaveType = _leaveTypeRepository.Get(input.LeaveRequest.LeaveTypeId);

            var entitlment =
                _leaveEntitlmentRepository.FirstOrDefault(ent => ent.LeaveTypeId == input.LeaveRequest.LeaveTypeId &&
                                                          ent.EmployeeId == input.LeaveRequest.EmployeeId && ent.PeriodId == period.Id);

            if (entitlment == null)
            {
                return(new OutputBase
                {
                    Message = string.Format("You are not entitled to any {0} for {1}", leaveType.Name, period.Range),
                    Success = false
                });
            }

            //check for pending leave request
            if (_leaveRequestRepository.Query(q => q.Any(lr => lr.EmployeeId == input.LeaveRequest.EmployeeId &&
                                                         lr.Status == LeaveRequestStatus.Pending)))
            {
                return(new OutputBase
                {
                    Message =
                        "You still have a pending leave request. " +
                        "You can either delete the request or wait untill it is processed to continue",
                    Success = false
                });
            }

            var duration = Math.Abs(new TimeStamp(input.LeaveRequest.StartDate, true).
                                    DaysDifference(new TimeStamp(input.LeaveRequest.EndDate)));
            var daysTaken =
                _leaveRepository.Query(
                    q =>
                    q.Any(
                        l =>
                        l.LeaveEntitlment.EmployeeId == input.LeaveRequest.EmployeeId &&
                        l.LeaveEntitlment.PeriodId == period.Id &&
                        l.LeaveEntitlment.LeaveTypeId == input.LeaveRequest.LeaveTypeId))
                    ? _leaveRepository.GetAll().Where(l =>
                                                      l.LeaveEntitlment.EmployeeId == input.LeaveRequest.EmployeeId &&
                                                      l.LeaveEntitlment.PeriodId == period.Id &&
                                                      l.LeaveEntitlment.LeaveTypeId == input.LeaveRequest.LeaveTypeId).Sum(l => l.NumberOfDays)
                    : 0;
            var daysLeft = entitlment.NumberOfDays - daysTaken;

            if (duration > daysLeft)
            {
                return new OutputBase
                       {
                           Message =
                               string.Format("You cannot take {3} days again. You have already taken {0} days from your {1}. You are now left with {2} days",
                                             daysTaken, leaveType.Name, daysLeft, duration),
                           Success = false
                       }
            }
            ;
            _leaveRequestRepository.Insert(new LeaveRequest
            {
                EmployeeId  = input.LeaveRequest.EmployeeId,
                EndDate     = input.LeaveRequest.EndDate,
                Status      = LeaveRequestStatus.Pending,
                StartDate   = input.LeaveRequest.StartDate,
                LeaveTypeId = input.LeaveRequest.LeaveTypeId,
                Note        = input.LeaveRequest.Note
            });
            return(new OutputBase {
                Message = "Request saved", Success = true
            });
        }
コード例 #4
0
 public bool Insert(LeaveRequestVM leaveRequstVM)
 {
     return(iLeaveRequesRepository.Insert(leaveRequstVM));
 }