コード例 #1
0
        public async Task <IActionResult> GetAll()
        {
            var leaves = await _repo.GetAll();

            var merged = leaves.Select(x => Map(x));

            return(Ok(merged));
        }
コード例 #2
0
ファイル: LeavesController.cs プロジェクト: xprasoulas/grid
        public JsonResult Index()
        {
            var apiResult = TryExecute(() =>
            {
                return(_leaveRepository.GetAll().Select(h => new LeaveModel(h)).ToList());
            }, "Leaves Fetched sucessfully");

            return(Json(apiResult, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
ファイル: LeaveController.cs プロジェクト: N412/esuhai
        public async Task <IActionResult> GetAll([FromQuery] UserParams userParams)
        {
            var leaves = await _repo.GetAll(userParams);

            var leavesForResponse = _mapper.Map <IEnumerable <UserForLeaveDto> >(leaves);

            Response.AddPagination(leaves.CurrentPage, leaves.PageSize, leaves.TotalCount, leaves.TotalPages);

            return(Ok(leavesForResponse));
        }
コード例 #4
0
 /// <summary>
 /// Retrieves the list of Leaves
 /// </summary>
 /// <returns></returns>
 public IEnumerable <Leave> GetLeaves()
 {
     return(_leaveRepository.GetAll());
 }
コード例 #5
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
            });
        }
コード例 #6
0
ファイル: LeaveService.cs プロジェクト: ATZakir/AttendanceNew
 public IEnumerable <Leave> GetAllLeave()
 {
     return(leaveRepository.GetAll());
 }