public async Task <ActionResult> Delete(int id, LeaveRequestViewModel model)
        {
            try
            {
                // TODO: Add delete logic here
                var leaveType = await _repo.FindById(id);

                if (leaveType == null)
                {
                    return(NotFound());
                }

                var isSuccess = await _repo.Delete(leaveType);

                if (!isSuccess)
                {
                    return(View(model));
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View(model));
            }
        }
Example #2
0
        // GET:
        public async Task <IActionResult> Permission(Guid id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var req = await _context.LeaveRequest.FindAsync(id);

            if (req == null)
            {
                return(NotFound());
            }

            var levReqView = new LeaveRequestViewModel()
            {
                LeaveRequestId   = req.LeaveRequestId,
                LeaveTypeName    = _context.LeaveType.SingleOrDefault(l => l.LeaveTypeId == req.LeaveTypeId).LeaveTypeName,
                From             = req.FromTimeOff,
                To               = req.ToTimeOff,
                Total            = req.TotalTimeOff,
                ReasonForAbsence = req.ReasonForAbsence,
                EmergencyContact = req.EmergencyContact,
                Requester        = _context.Employee.SingleOrDefault(e => e.EmployeeId == req.RequesterId).Email,
                RequestedDate    = req.RequestedDate,
                Status           = req.Status,
                Remark           = req.Remark
            };

            return(View(levReqView));
        }
        public async Task <IActionResult> Create([Bind("Id,CurrentYear,LeaveFromDate,LeaveToDate,LeaveTotalDay,HalfDay,HalfStatus,Status,Description,UnPaidLeaveStatus,PayRollStatus,LeaveTypeId")] LeaveRequestViewModel leaveRequest)
        {
            if (ModelState.IsValid)
            {
                LeaveRequest ll = new LeaveRequest()
                {
                    CurrentYear       = leaveRequest.CurrentYear,
                    LeaveFromDate     = leaveRequest.LeaveFromDate,
                    LeaveToDate       = leaveRequest.LeaveToDate,
                    LeaveTotalDay     = leaveRequest.LeaveTotalDay,
                    HalfDay           = leaveRequest.HalfDay,
                    HalfStatus        = leaveRequest.HalfStatus,
                    Status            = leaveRequest.Status,
                    UnPaidLeaveStatus = leaveRequest.UnPaidLeaveStatus,
                    PayRollStatus     = leaveRequest.PayRollStatus,
                    LeaveTypeId       = leaveRequest.LeaveTypeId
                };
                //_context.Add(leaveRequest);
                //await _context.SaveChangesAsync();
                await leaveRequestRepository.Save(ll);

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LeaveTypeId"] = new SelectList(leaveTypeRepository.GetLeaveTypeList(), "Id", "Id", leaveRequest.LeaveTypeId);
            return(View(leaveRequest));
        }
Example #4
0
        public ActionResult ChangeLeaveRequestApprovalStatusHR(LeaveRequestViewModel leaveRequestInfo)
        {
            if (leaveRequestInfo == null)
            {
                throw new ArgumentNullException(nameof(leaveRequestInfo));
            }

            //Check Model State
            if (!ModelState.IsValid)
            {
                var model = leaveRequestService.GetLeaveRequestUpdateView(leaveRequestInfo, string.Empty);

                return(PartialView("ChangeLeaveRequestApprovalStatusHR", model));
            }

            var processingMessage = leaveRequestService.ProcessLeaveRequestApprovalStatusChangeHr(leaveRequestInfo);

            if (!string.IsNullOrEmpty(processingMessage))
            {
                var model = leaveRequestService.GetLeaveRequestUpdateView(leaveRequestInfo, string.Empty);

                return(this.View("ChangeLeaveRequestApprovalStatusHR", model));
            }

            return(Redirect(leaveRequestInfo.URL));
        }
        public ActionResult ApproveLeaveRequest(LeaveRequestViewModel model)
        {
            model.ActionManagerId = EmployeeId;
            LeaveRequestService.Instance.ApproveLeaveRequest(model);

            return(Json(new { data_url = "LeaveRequest/LeaveRequests" }));
        }
        public async Task <ActionResult> Details(LeaveRequestViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                var user = await _userManager.GetUserAsync(User);

                var leaveRequest = await _unitOfWork.LeaveRequests.Find(q => q.Id == model.Id);

                leaveRequest.Approved        = false;
                leaveRequest.ApprovedById    = user.Id;
                leaveRequest.DateActioned    = DateTime.Now;
                leaveRequest.ApproverComment = model.ApproverComment;

                _unitOfWork.LeaveRequests.Update(leaveRequest);
                await _unitOfWork.Save();

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "Something went wrong");
                return(View(model));
            }
        }
        public ActionResult RequestLeave(LeaveRequestViewModel model)
        {
            var leaveName = leavemanagerRepo.GetLeaveDetails(model.LeavetypeId.Value);
            var getPreviousAppliedDateNo = leavemanagerRepo.GetLeaveAppliedFor(model.UserId);
            var validLeave = leavemanagerRepo.CheckIfLeaveIsFinished(model.UserId, (int)model.requestDays, int.Parse(model.AvailableLeave));

            if (ModelState.IsValid && leaveName != null && validLeave != true)
            {
                LeaveRequest leave = new LeaveRequest();
                leave.UserId             = model.UserId.ToString();
                leave.RepmangId          = model.RepmangId;
                leave.NoOfDays           = model.LeaveNoOfDays;
                leave.ToDate             = model.ToDate;
                leave.FromDate           = model.FromDate;
                leave.Reason             = model.Reason;
                leave.LeavetypeId        = model.LeavetypeId;
                leave.createdby          = User.Identity.GetUserId();
                leave.modifiedby         = User.Identity.GetUserId();
                leave.createddate        = DateTime.Now;
                leave.modifieddate       = DateTime.Now;
                leave.isactive           = true;
                leave.LeaveStatus        = null;
                leave.LeaveName          = leaveName.leavetype;
                leave.Availableleave     = int.Parse(model.AvailableLeave);
                leave.AppliedleavesCount = +model.requestDays + getPreviousAppliedDateNo; //Remember to do this with the modelState to check if leave is finished
                leave.requestDaysNo      = model.requestDays;
                leaveRepo.AddLeaveRequest(leave);
                return(RedirectToAction("Leave", "selfService")); //redirect to employee selservice page for him to see his requests
            }
            TempData["Error"] = "Something went wrong";
            ViewBag.leaveType = new SelectList(leaveRepo.GetLeaveTypes().OrderBy(x => x.leavetype), "id", "leavetype", "id");
            ViewBag.userId    = User.Identity.GetUserId();
            ModelState.AddModelError("", "Please make sure your leave your leave hasn't been exhausted or you can ask The HR to assign more leave for you.");
            return(View(model));
        }
        public ActionResult Create(CreateLeaveRequestViewModel model)
        {
            try
            {
                // TODO: Add insert logic here
                var leaveTypes     = _leaveTypeRepo.FindAll();
                var leaveTypeItems = leaveTypes.Select(q => new SelectListItem
                {
                    Text  = q.Name,
                    Value = q.Id.ToString()
                });
                model.LeaveTypes = leaveTypeItems;
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                if (DateTime.Compare(model.StartDate, model.EndDate) > 1)
                {
                    ModelState.AddModelError("", "Invalid Date selection...");
                    return(View(model));
                }

                var employee      = _userManager.GetUserAsync(User).Result;
                var allocation    = _leaveAllocationRepo.GetLeaveAllocationsByEmployeeAndType(employee.Id, model.LeaveTypeId);
                var daysRequested = (int)(model.EndDate.Date - model.StartDate.Date).TotalDays;

                if (daysRequested > allocation.NumberOfDays)
                {
                    ModelState.AddModelError("", "You Do not have sufficien days for this request.");
                    return(View(model));
                }

                var leaveRequest = new LeaveRequestViewModel
                {
                    RequestingEmployeeId = employee.Id,
                    StartDate            = model.StartDate,
                    EndDate       = model.EndDate,
                    Approved      = null,
                    DateRequested = DateTime.Now,
                    DateActioned  = DateTime.Now,
                    LeaveTypeId   = model.LeaveTypeId
                };

                var leaveRequst = _mapper.Map <LeaveRequest>(leaveRequest);
                var isSuccess   = _leaveRequestRepo.Create(leaveRequst);
                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Something went wrong");
                    return(View());
                }


                return(RedirectToAction("UserLeaveRequests"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "Something went wrong");
                return(View());
            }
        }
Example #9
0
        public ActionResult CreateLeaveRequest(LeaveRequestViewModel leaveRequestInfo)
        {
            if (leaveRequestInfo == null)
            {
                throw new ArgumentNullException(nameof(leaveRequestInfo));
            }

            //Check Model State
            if (!ModelState.IsValid)
            {
                var model = leaveRequestService.GetLeaveRequestUpdateView(leaveRequestInfo, string.Empty);

                return(this.View("CreateLeaveRequest", model));
            }

            var processingMessage = leaveRequestService.ProcessLeaveRequestCreate(leaveRequestInfo);

            if (!string.IsNullOrEmpty(processingMessage))
            {
                var model = leaveRequestService.GetLeaveRequestUpdateView(leaveRequestInfo, processingMessage);

                return(this.View("CreateLeaveRequest", model));
            }

            var returnMessage = string.Format("You've create a new leave request");

            return(Redirect(leaveRequestInfo.URL));
        }
Example #10
0
        public async Task <IActionResult> Permission(Guid id, [Bind("LeaveRequestId,LeaveTypeName,From,To,Total,ReasonForAbsence,EmergencyContact,EmergencyContactName,EmergencyContactRS,Requester,RequestedDate,Status,Remark")] LeaveRequestViewModel model, string btnStatus)
        {
            if (ModelState.IsValid)
            {
                var req = _context.LeaveRequest.SingleOrDefault(l => l.LeaveRequestId == id);
                if (req == null)
                {
                    return(NotFound());
                }

                if (btnStatus.Equals("Approve"))
                {
                    var balance = _context.Balance.SingleOrDefault(b => b.EmployeeId == req.RequesterId && b.LeaveTypeId == req.LeaveTypeId);
                    balance.UsedBalance     = Convert.ToDecimal(utilities.CalculateHolidays(req.FromTimeOff, req.ToTimeOff));
                    balance.RemainedBalance = Convert.ToDecimal(utilities.CalculateBalance(req.RequesterId, balance.LeaveTypeId, req.FromTimeOff, req.ToTimeOff));
                    balance.UpdatedBy       = null;
                    balance.UpdatedDate     = null;

                    _context.Update(balance);
                    await _context.SaveChangesAsync();
                }

                req.Status         = btnStatus.Equals("Approve") ? RequestStatus.APPROVED : RequestStatus.REJECTED;
                req.Remark         = model.Remark;
                req.AuthorizerId   = _context.Employee.SingleOrDefault(e => e.Email == _email).EmployeeId;
                req.AuthorizedDate = DateTime.Now;

                _context.Update(req);
                await _context.SaveChangesAsync();
            }

            return(RedirectToAction(nameof(Index)));
        }
        // GET: LeaveRequestController/Details/5
        public async Task <ActionResult> Details(int id)
        {
            LeaveRequest leaveRequest = await _leaveRequestRepo.FindById(id);

            LeaveRequestViewModel model = _mapper.Map <LeaveRequestViewModel>(leaveRequest);

            return(View(model));
        }
        public ActionResult Create(CreateLeaveRequestViewModel model)
        {
            try
            {
                var startDate      = Convert.ToDateTime(model.StartDate);
                var endDate        = Convert.ToDateTime(model.EndDate);
                var leaveTypes     = _leaveTypeRepository.FindAll();
                int daysRequested  = (int)(endDate - startDate).TotalDays;
                var leaveTypeItems = leaveTypes.Select(q => new SelectListItem
                {
                    Text  = q.Name,
                    Value = q.Id.ToString()
                });
                model.LeaveTypes = leaveTypeItems;
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                if (DateTime.Compare(startDate, endDate) > 1)
                {
                    ModelState.AddModelError("", "Start Date cannot be further in the future than the End Date");
                    return(View(model));
                }
                var employee   = _userManager.GetUserAsync(User).Result;
                var allocation = _leaveAllocationRepository.GetLeaveAllocationsByEmployeeAndType(employee.Id, model.LeaveTypeId);
                if (daysRequested > allocation.NumberofDays)
                {
                    ModelState.AddModelError("", "You Do Not Have Sufficient Days For This Request");
                }

                var leaveRequestModel = new LeaveRequestViewModel
                {
                    RequestingEmployeeId = employee.Id,
                    StartDate            = startDate,
                    EndDate       = endDate,
                    Approved      = null,
                    DateRequested = DateTime.Now,
                    DateActioned  = DateTime.Now,
                    LeaveTypeId   = model.LeaveTypeId
                };

                var leaveRequest = _mapper.Map <LeaveRequest>(leaveRequestModel);
                var isSuccess    = _leaveRequestRepository.Create(leaveRequest);

                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Something went wrong with submitting your record");
                    return(View(model));
                }

                return(RedirectToAction("MyLeave"));
            }
            catch
            {
                return(View());
            }
        }
Example #13
0
        // POST: LeaveRequest
        public async Task <ActionResult> ApplyForLeave()
        {
            LeaveRequestViewModel leaveRequestViewModel = new LeaveRequestViewModel();
            List <LeaveType>      leaveTypes            = await _leaveTypeRepo.GetAllLeaveTypes();

            var leaveTypeViewModel = _mapper.Map <List <LeaveType>, List <LeaveTypesVM> >(leaveTypes);

            leaveRequestViewModel.LeaveTypes = leaveTypeViewModel;
            return(View(leaveRequestViewModel));
        }
        public ActionResult UpdateLeaveRequest(LeaveRequestViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            LeaveRequestService.Instance.UpdateLeaveRequest(model);

            return(RedirectToAction("LeaveRequests", "LeaveRequest"));
        }
        public ActionResult CreateLeaveRequest(LeaveRequestViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            model.EmployeeId = EmployeeId;
            LeaveRequestService.Instance.CreateLeaveRequest(model);

            return(RedirectToAction("LeaveRequests", "LeaveRequest"));
        }
Example #16
0
        public LeaveRequestViewModel MapToLeaveRequestViewModel(LeaveRequest leaveRequest)
        {
            if (leaveRequest == null)
            {
                return(null);
            }

            LeaveRequestViewModel leaveRequestViewModel = new LeaveRequestViewModel
            {
                LeaveRequestId  = leaveRequest.LeaveRequestId,
                EmployeeId      = leaveRequest.EmployeeId,
                ActionManagerId = leaveRequest.ActionManagerId,
                LeaveFrom       = leaveRequest.LeaveFrom,
                LeaveFromText   = leaveRequest.LeaveFrom.ToString(Constants.DisplayDateFormat),
                LeaveTo         = leaveRequest.LeaveTo,
                LeaveToText     = leaveRequest.LeaveTo.ToString(Constants.DisplayDateFormat),
                LeaveReason     = leaveRequest.LeaveDescription,
                StatusId        = leaveRequest.RequestStatusId,
                StatusCode      = leaveRequest.RequestStatu.RequestStatusCode,
                StatusName      = leaveRequest.RequestStatu.RequestStatusName
            };

            if (leaveRequest.Employee != null)
            {
                leaveRequestViewModel.EmployeeName = leaveRequest.Employee.FullName;
            }

            if (leaveRequest.ActionManager != null)
            {
                leaveRequestViewModel.ActionManagerName = leaveRequest.ActionManager.FullName;
            }

            Status status = (Status)Enum.Parse(typeof(Status), leaveRequestViewModel.StatusCode);

            switch (status)
            {
            case Status.APPROVED:
                leaveRequestViewModel.StatusName = string.Format("Approved by: {0}", leaveRequestViewModel.ActionManagerName);
                break;

            case Status.DECLINED:
                leaveRequestViewModel.StatusName = string.Format("Declined by: {0}", leaveRequestViewModel.ActionManagerName);
                break;

            case Status.PENDING:
                leaveRequestViewModel.IsPending  = true;
                leaveRequestViewModel.StatusName = "Pending approval";
                break;
            }

            return(leaveRequestViewModel);
        }
Example #17
0
        public IActionResult CreateLeaveRequest()
        {
            LeaveRequestViewModel obj = new LeaveRequestViewModel();

            try
            {
                string firsttimelogin = HttpContext.Session.GetString("FirstTimeLogin");
                if (firsttimelogin == null)
                {
                    GetApprover(obj);
                    HttpContext.Session.SetString("FirstTimeLogin", "yes");
                }
                else
                {
                    string EmpID        = HttpContext.Session.GetString(Constant.EmployeeID);
                    var    returnresult = Mapper.Map <DeptLeaveRequestViewModel>(_IDeptLeaveRequestViewService.GetEmpDetails(EmpID));
                    obj.ApproverId   = returnresult.ApproverId.Split('_')[0];
                    obj.ApproverName = returnresult.ApproverId.Split('_')[1];
                }
                List <SelectListItem> leaveList = new List <SelectListItem>();
                ViewBag.IsChangeLeave = "No";
                string editleaveid = Convert.ToString(TempData["LeaveData"]);
                if (editleaveid != "")
                {
                    obj = Mapper.Map <List <LeaveRequestViewModel> >(_ILeaveRequestViewService.GetLeaveDetailsForChange(Convert.ToInt32(editleaveid))).FirstOrDefault();
                    ViewBag.IsChangeLeave = "Yes";
                }
                obj.PA       = HttpContext.Session.GetString(Constant.PersonalArea);
                obj.PSA      = HttpContext.Session.GetString(Constant.PersonalSubArea);
                obj.Category = HttpContext.Session.GetString(Constant.Category);
                var LeaveCategoryList = _ILeaveRequestViewService.GetLeaveRequest(obj.PA, obj.PSA, obj.Category);
                obj.Leavelist = LeaveCategoryList;
                if (editleaveid != "")
                {
                    obj.Leavelist.Find(x => x.Text == obj.LeaveCategory).Selected = true;
                }
                if (obj.ApproverId.Length != 8)
                {
                    obj.ApproverId = obj.ApproverId.ToString().PadLeft(8, '0');
                }
                obj.ApproverName = obj.ApproverId + '_' + obj.ApproverName;
                obj.EmployeeName = HttpContext.Session.GetString(Constant.SessionUserName);
                return(View((obj)));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                return(View((obj)));
            }
        }
Example #18
0
        /// <summary>
        /// Creates the leave request update view.
        /// </summary>
        /// <param name="leaveRequestInfo">The leave request information.</param>
        /// <param name="viewModelData">The view model data.</param>
        /// <returns></returns>
        public ILeaveRequestViewModel CreateLeaveRequestUpdateView(ILeaveRequestViewModel leaveRequestInfo, Hashtable viewModelData)
        {
            // Extract relevant data from the viewModelData
            var leaveTypeCollection    = viewModelData["leaveTypeCollection"] as List <ILeaveType>;
            var leaveStatusCollection  = viewModelData["leaveStatusCollection"] as List <ILeaveStatus>;
            var processingMessage      = (string)viewModelData["processingMessage"];
            var employeeName           = (string)viewModelData["employeeName"];
            var approvingAuthorityName = (string)viewModelData["approvingAuthorityName"];
            var hrApproverName         = (string)viewModelData["hrApproverName"];
            var leaveStatusName        = (string)viewModelData["leaveStatusName"];
            var leaveTypeName          = (string)viewModelData["leaveTypeName"];
            var annualLeaveDuration    = (int)viewModelData["annualLeaveDuration"];
            var employeeId             = (int)viewModelData["employeeId"];

            // Get the dropdown list items
            var leaveTypeDDL   = GetDropDownList.LeaveTypeListItems(leaveTypeCollection, leaveRequestInfo.LeaveTypeID);
            var leaveStatusDDL = GetDropDownList.LeaveStatusListItems(leaveStatusCollection, leaveRequestInfo.LeaveStatusID);

            var viewModel = new LeaveRequestViewModel
            {
                ProcessingMessage   = processingMessage,
                LeaveTypeDropDown   = leaveTypeDDL,
                LeaveStatusDropDown = leaveStatusDDL,

                LeaveID                   = leaveRequestInfo.LeaveID,
                EmployeeID                = leaveRequestInfo.EmployeeID,
                LeaveTypeID               = leaveRequestInfo.LeaveTypeID,
                DateLeaveStart            = leaveRequestInfo.DateLeaveStart,
                DateLeaveEnds             = leaveRequestInfo.DateLeaveEnds,
                Comment                   = leaveRequestInfo.Comment,
                LeaveStatusID             = leaveRequestInfo.LeaveStatusID,
                DateRequested             = leaveRequestInfo.DateRequested,
                ApprovingAuthorityID      = leaveRequestInfo.ApprovingAuthorityID,
                HRApproverID              = leaveRequestInfo.HRApproverID,
                ApprovingAuthorityComment = leaveRequestInfo.ApprovingAuthorityComment,
                HRApproverComment         = leaveRequestInfo.HRApproverComment,
                DateApprovedDept          = leaveRequestInfo.DateApprovedDept,
                DateApprovedHR            = leaveRequestInfo.DateApprovedHR,
                DateCreated               = leaveRequestInfo.DateCreated,

                EmployeeName           = employeeName,
                ApprovingAuthorityName = approvingAuthorityName,
                HRApproverName         = hrApproverName,
                LeaveStatusName        = leaveStatusName,
                LeaveTypeName          = leaveTypeName,
                AnnualLeaveDuration    = annualLeaveDuration
            };

            return(viewModel);
        }
Example #19
0
 /// <summary>
 /// Get Holiday
 /// </summary>
 /// <returns></returns>
 public JsonResult GetHolidayList()
 {
     try
     {
         LeaveRequestViewModel objModel = new LeaveRequestViewModel();
         objModel.EmployeeID = HttpContext.Session.GetString(Constant.EmployeeID);
         var holidaylist = _ILeaveRequestViewService.GetHolidayList(objModel.EmployeeID);
         return(Json(holidaylist));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, ex.Message);
         return(Json(string.Empty));
     }
 }
Example #20
0
 /// <summary>
 /// For Leave Bind in Dropdown
 /// </summary>
 /// <returns></returns>
 public JsonResult GetLeaveRequestList()
 {
     try
     {
         LeaveRequestViewModel obj = new LeaveRequestViewModel();
         obj.PA  = HttpContext.Session.GetString(Constant.PersonalArea);
         obj.PSA = HttpContext.Session.GetString(Constant.PersonalSubArea);
         var leaveList = _ILeaveRequestViewService.GetLeaveRequest(obj.PA, obj.PSA, obj.Category);
         return(Json(leaveList));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, ex.Message);
         return(Json(string.Empty));
     }
 }
Example #21
0
        public async Task <IActionResult> RequestLeave([FromBody] LeaveRequestViewModel leave)
        {
            if (leave == null)
            {
                return(BadRequest("Invalid request params"));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var request = this.ObjectFactory.Create <LeaveServiceObject>(leave);

            var result = await this.LeaveManagementService.RequestLeaveAsync(request);

            return(Created("api/v1/leaves", this.ViewModelFactory.Create <LeaveResponseViewModel>(result)));
        }
        public IActionResult Details(LeaveRequestViewModel model)
        {
            var request = _mapper.Map <LeaveRequest>(model);

            request.RequestingEmployee = _employeeRepository.FindById(Guid.Parse(model.RequestingEmployeeId));
            request.ApprovedBy         = _employeeRepository.FindById(Guid.Parse(_userManager.GetUserAsync(User).Result.Id));
            request.LeaveType          = _leaveTypeRepository.FindById(model.LeaveTypeId);
            if (request.Approved == true)
            {
                var allocation = _leaveAllocationRepository.GetLeaveAllocationByEmployeeAndLeaveType(request.RequestingEmployee.Id, request.LeaveType.Id);
                allocation.NumberOfDays -= (int)(request.EndDate - request.StartDate).TotalDays;

                _leaveAllocationRepository.Update(allocation);
            }

            _leaveRequestRepository.Update(request);


            return(RedirectToAction("Index"));
        }
Example #23
0
        /// <summary>
        /// Creates the selected leave request view.
        /// </summary>
        /// <param name="leaveRequestInfo">The leave request information.</param>
        /// <param name="viewModelData">The view model data.</param>
        /// <returns></returns>
        public ILeaveRequestViewModel CreateSelectedLeaveRequestView(ILeaveRequestModel leaveRequestInfo, IEmployee employee, IGrade grade,
                                                                     ILeaveType leaveType, IList <ILeaveType> leaveTypeCollection, IList <ILeaveStatus> leaveStatusCollection, string processingMessage)
        {
            var leaveTypeDDL   = GetDropDownList.LeaveTypeListItems(leaveTypeCollection, leaveRequestInfo.LeaveTypeId);
            var leaveStatusDDL = GetDropDownList.LeaveStatusListItems(leaveStatusCollection, leaveRequestInfo.LeaveStatusId);

            var viewModel = new LeaveRequestViewModel
            {
                ProcessingMessage   = processingMessage,
                LeaveTypeDropDown   = leaveTypeDDL,
                LeaveStatusDropDown = leaveStatusDDL,

                LeaveID                   = leaveRequestInfo.LeaveId,
                EmployeeID                = leaveRequestInfo.EmployeeId,
                LeaveTypeID               = leaveRequestInfo.LeaveTypeId,
                DateLeaveStart            = leaveRequestInfo.DateLeaveStart,
                DateLeaveEnds             = leaveRequestInfo.DateLeaveEnds,
                Comment                   = leaveRequestInfo.Comment,
                LeaveStatusID             = leaveRequestInfo.LeaveStatusId,
                DateRequested             = leaveRequestInfo.DateRequested,
                ApprovingAuthorityID      = leaveRequestInfo.ApprovingAuthorityId,
                HRApproverID              = leaveRequestInfo.HRApproverId,
                ApprovingAuthorityComment = leaveRequestInfo.ApprovingAuthorityComment,
                HRApproverComment         = leaveRequestInfo.HRApproverComment,
                DateApprovedDept          = leaveRequestInfo.DateApprovedDept,
                DateApprovedHR            = leaveRequestInfo.DateApprovedHR,
                DateCreated               = leaveRequestInfo.DateCreated,
                LeaveType                 = leaveType,
                EmployeeName              = employee.LastName + " " + employee.FirstName,
                LeaveStatusName           = leaveRequestInfo.LeaveStatusName,
                LeaveTypeName             = leaveRequestInfo.LeaveTypeName,
                CompanyId                 = leaveRequestInfo.CompanyId,

                AnnualLeaveDuration = grade.AnnualLeaveDuration,
                Grade = grade
            };

            return(viewModel);
        }
Example #24
0
        /// <summary>
        /// Creates the leave request creation view.
        /// </summary>
        /// <param name="viewModelData">The view model data.</param>
        /// <returns></returns>
        public ILeaveRequestViewModel CreateLeaveRequestCreationView(IEmployee employee, IGrade grade, IList <ILeaveType> leaveTypeCollection, IList <ILeaveStatus> leaveStatusCollection, string processingMessage)
        {
            // Extract relevant data from the view


            var leaveTypeDDL   = GetDropDownList.LeaveTypeListItems(leaveTypeCollection, -1);
            var leaveStatusDDL = GetDropDownList.LeaveStatusListItems(leaveStatusCollection, -1);

            var viewModel = new LeaveRequestViewModel
            {
                ProcessingMessage   = processingMessage,
                LeaveTypeDropDown   = leaveTypeDDL,
                LeaveStatusDropDown = leaveStatusDDL,
                EmployeeID          = employee.EmployeeId,
                DateRequested       = DateTime.Now,
                DateCreated         = DateTime.Now,
                AnnualLeaveDuration = grade.AnnualLeaveDuration,
                CompanyId           = employee.CompanyId
            };

            return(viewModel);
        }
Example #25
0
 public JsonResult SaveAlternateApprover(LeaveRequestViewModel model)
 {
     try
     {
         string           EmpID = HttpContext.Session.GetString(Constant.EmployeeID);
         Zftm0006Response z     = new Zftm0006Response();
         z.DETAILS    = new ZFTM0006_TAB[6];
         z.DETAILS[0] = new ZFTM0006_TAB();
         if (_rfcconfig.GetSection("StaticValue").GetSection("EMobNo").Value != "")
         {
             z.DETAILS[0].CELL_SUP    = _rfcconfig.GetSection("StaticValue").GetSection("EMobNo").Value;
             z.DETAILS[0].EMAIL_SUP   = _rfcconfig.GetSection("StaticValue").GetSection("EmailApr").Value;
             z.DETAILS[0].EMAILID_HOD = _rfcconfig.GetSection("StaticValue").GetSection("EMailHOD").Value;
             z.DETAILS[0].PERNR_SUP   = _rfcconfig.GetSection("StaticValue").GetSection("AprID").Value;
             z.DETAILS[0].CNAME_SUP   = _rfcconfig.GetSection("StaticValue").GetSection("AprName").Value;
         }
         else
         {
             z.DETAILS[0].PERNR_SUP   = model.ApproverId.Trim();
             z.DETAILS[0].CNAME_SUP   = model.ApproverName.Trim();
             z.DETAILS[0].CELL_SUP    = model.ApproverMobNo.Trim();
             z.DETAILS[0].EMAIL_SUP   = model.ApproverMailID.Trim();
             z.DETAILS[0].EMAILID_HOD = model.HODMailID.Trim();
         }
         z.DETAILS[0].PERNR_HOD      = model.HODID;
         z.DETAILS[0].CNAME_HOD      = model.HODName;
         z.DETAILS[0].EmployeeID     = EmpID;
         z.DETAILS[0].LeaveRequestID = model.LeaveRequestId;
         var datareturn = _ILeaveRequestViewService.SaveApproverFromSAP(Mapper.Map <ApproverServiceModel>(z));
         var msg        = "saved";
         return(Json(msg));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, ex.Message);
         return(Json(string.Empty));
     }
 }
        public async Task <IActionResult> Create([Bind("LeaveFromDate,LeaveToDate,Description,LeaveTotalDay,HalfDay,UnPaidLeaveStatus,LeaveRemainDay,LeaveTypeId,FromEmployeeInfoId,ToEmployeeInfoId")] LeaveRequestViewModel leaveRequest)
        {
            if (ModelState.IsValid)
            {
                LeaveRequest ll = new LeaveRequest()
                {
                    CurrentYear        = DateTime.Now.Year,
                    LeaveFromDate      = leaveRequest.LeaveFromDate,
                    LeaveToDate        = leaveRequest.LeaveToDate,
                    LeaveTotalDay      = leaveRequest.LeaveTotalDay,
                    HalfDay            = leaveRequest.HalfDay.ToString(),
                    Description        = leaveRequest.Description,
                    Status             = LeaveStatus.Pending.ToString(),
                    UnPaidLeaveStatus  = leaveRequest.UnPaidLeaveStatus.ToString(),
                    LeaveRemainDay     = leaveRequest.LeaveRemainDay,
                    FromEmployeeInfoId = leaveRequest.FromEmployeeInfoId,
                    ToEmployeeInfoId   = leaveRequest.ToEmployeeInfoId
                };
                if (leaveRequest.UnPaidLeaveStatus)
                {
                    ll.LeaveType = null;
                }
                else
                {
                    ll.LeaveTypeId = leaveRequest.LeaveTypeId;
                }

                await leaveRequestRepository.Save(ll);

                return(RedirectToAction(nameof(Index)));
            }
            /*ViewBag.Message = ModelState.ErrorCount + ">>>>> ";*/
            ViewData["LeaveTypeId"]        = new SelectList(leaveTypeRepository.GetLeaveTypeList(), "Id", "TypeName", leaveRequest.LeaveTypeId);
            ViewData["FromEmployeeInfoId"] = new SelectList(employeeInfoRepository.GetEmployeeInfoList(), "Id", "EmployeeName", leaveRequest.FromEmployeeInfoId);
            ViewData["ToEmployeeInfoId"]   = new SelectList(employeeInfoRepository.GetEmployeeInfoList(), "Id", "EmployeeName", leaveRequest.ToEmployeeInfoId);
            return(View(leaveRequest));
        }
Example #27
0
        public IActionResult UpdateLeaveRequest(string Approver, string LeaverequestID)
        {
            string msg = "";

            try
            {
                LeaveRequestViewModel objModel = new LeaveRequestViewModel();
                string[] arrApproverName       = Approver.Split('_');
                int      objArrCount           = arrApproverName.Length;
                if (objArrCount > 1)
                {
                    var objApproverId   = arrApproverName[0].ToString();
                    var objApproverName = arrApproverName[1].ToString();
                    objModel.ApproverId   = objApproverId;
                    objModel.ApproverName = objApproverName;
                }
                objModel.LeaveRequestId = LeaverequestID;
                objModel.EmployeeID     = HttpContext.Session.GetString(Constant.EmployeeID);
                Tuple <string, int> Result = _ILeaveRequestViewService.SaveLeaveRequest(Mapper.Map <LeaveRequestViewtServiceModel>(objModel));
                if (Result.Item2 == 1)
                {
                    msg = "success" + "~" + Result.Item1;
                }
                else
                {
                    msg = "danger" + "~" + Result.Item1;
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                msg = "danger" + "~" + "Error occured while processing leave request...............";
            }
            TempData["Messages"] = msg;
            //return RedirectToAction("LeaveDashboard", "LeaveDashboard");
            return(Json(new { msg = msg }));
        }
Example #28
0
        public async Task <ActionResult> Create(CreateLeaveRequestViewModel model)
        {
            try
            {
                /* Loads in the leaveTypes data again in the event of
                 * model evaluation returning a result that is not valid.
                 * This allows us to return the view with model without
                 * returning with missing data which would be a poor UX.
                 */
                var leaveTypes = await _leaveTypeRepo.FindAll();

                var leaveTypeItems = leaveTypes.Select(q => new SelectListItem {
                    Text = q.Name, Value = q.Id.ToString()
                });

                model.LeaveTypes = leaveTypeItems;

                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                /* Date selection validation 1:
                 * Checks that the end date is not before the start date
                 * if so it returns to the view and doesn't process.
                 */
                if (DateTime.Compare(model.StartDate, model.EndDate) > 1)
                {
                    ModelState.AddModelError("", "The end date cannot be before the start date.");
                    return(View(model));
                }


                /* load up the:
                 * user details
                 * allocation type
                 * number of days requested
                 */
                var employee   = _userManager.GetUserAsync(User).Result;
                var allocation = await _allocationsRepo.GetLeaveAllocationsByEmployeeAndType(employee.Id, model.LeaveTypeId);

                int daysRequested = (int)(model.EndDate - model.StartDate).TotalDays;

                /* Date selection validation 2:
                 * Checks that the end date is not before the start date
                 * if so it returns to the view and doesn't process.
                 */
                if (daysRequested > allocation.NumberOfDays)
                {
                    ModelState.AddModelError("", "Insufficient allocation exists to process the request");
                    return(View(model));
                }

                var leaveRequestModel = new LeaveRequestViewModel
                {
                    RequestingEmployeeId = employee.Id,
                    LeaveTypeId          = model.LeaveTypeId,
                    StartDate            = model.StartDate,
                    EndDate       = model.EndDate,
                    Approved      = null,
                    Cancelled     = false,
                    DateRequested = DateTime.Now.Date
                };

                var leaveRequest = _mapper.Map <LeaveRequest>(leaveRequestModel);
                var isSuccess    = await _leaveRequestRepo.Create(leaveRequest);

                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Insufficient allocation exists to process the request");
                    return(View(model));
                }

                return(RedirectToAction("MyLeave"));
            }
            catch
            {
                ModelState.AddModelError("", "Error sending new leave request");
                return(View(model));
            }
        }
Example #29
0
        public ActionResult Create(CreateLeaveRequestViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var errormodel = GetCreateLeaveRequestVM();
                    return(View(errormodel));
                }

                if (model.StartDate >= model.EndDate)
                {
                    var errormodel = GetCreateLeaveRequestVM();
                    ModelState.AddModelError("", "Start date must be smaller than end date.");
                    return(View(errormodel));
                }

                var numberOfDays = (int)(model.EndDate.Date - model.StartDate.Date).TotalDays;


                var employee   = _userManager.GetUserAsync(User).Result;
                var allocation = _leaveAllocationRepo.GetLeaveAllocationsByEmployeeIdandLeaveType(employee.Id, model.LeaveTypeId, DateTime.Now.Year).FirstOrDefault();

                if (numberOfDays > allocation.NumberofDays)
                {
                    var errormodel = GetCreateLeaveRequestVM();
                    ModelState.AddModelError("", "Not enough remaining days.");
                    return(View(errormodel));
                }

                allocation.NumberofDays -= numberOfDays;
                var request = new LeaveRequestViewModel()
                {
                    RequestingEmployeeId = employee.Id,
                    StartDate            = model.StartDate,
                    EndDate       = model.EndDate,
                    DateRequested = DateTime.UtcNow,
                    Approved      = null,
                    DateActioned  = DateTime.UtcNow,
                    LeaveTypeId   = model.LeaveTypeId
                };

                var op1 = _repo.Create(_mapper.Map <LeaveRequest>(request));
                var op2 = _leaveAllocationRepo.Update(allocation);

                if (!op1 || !op2)
                {
                    var errormodel = GetCreateLeaveRequestVM();
                    ModelState.AddModelError("", "Error during save.");
                    return(View(errormodel));
                }

                return(RedirectToAction(nameof(Index), "Home"));
            }
            catch
            {
                ModelState.AddModelError("", "Operation Error");
                var errormodel = GetCreateLeaveRequestVM();
                return(View(errormodel));
            }
        }
        public List <LeaveRequestViewModel> GetLeaveData(int locationId, string employeeId, int month, int year, int TenantId, string leaveType, bool status)
        {
            List <LeaveRequestViewModel> leaveDataView = new List <LeaveRequestViewModel>();
            IEnumerable <LeaveRequest>   leaveData     = new List <LeaveRequest>();

            if (locationId == 0)
            {
                if (month == 0)
                {
                    if (leaveType == "All")
                    {
                        leaveData = employeeId == "0" ? FindAllByCondition(x => x.FromDate.Year == year || x.ToDate.Year == year).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Person.IsActive == status).ToList() :
                                    FindAllByCondition(x => x.FromDate.Year == year || x.ToDate.Year == year).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.Person.EmployeeCode == employeeId && x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Person.IsActive == status).ToList();
                    }
                    else if (leaveType == "Pending")
                    {
                        leaveData = employeeId == "0" ? FindAllByCondition(x => x.FromDate.Year == year || x.ToDate.Year == year).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.TenantId == TenantId && x.Person.Location.IsActive == true && (x.Status == leaveType || x.Status == "Requested For Cancel") && x.Person.IsActive == status).ToList() :
                                    FindAllByCondition(x => x.FromDate.Year == year || x.ToDate.Year == year).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.Person.EmployeeCode == employeeId && x.TenantId == TenantId && x.Person.Location.IsActive == true && (x.Status == leaveType || x.Status == "Requested For Cancel") && x.Person.IsActive == status).ToList();
                    }
                    else if (leaveType == "Approved")
                    {
                        leaveData = employeeId == "0" ? FindAllByCondition(x => x.FromDate.Year == year || x.ToDate.Year == year).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Status.StartsWith(leaveType) && x.Person.IsActive == status).ToList() :
                                    FindAllByCondition(x => x.FromDate.Year == year || x.ToDate.Year == year).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.Person.EmployeeCode == employeeId && x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Status.StartsWith(leaveType) && x.Person.IsActive == status).ToList();
                    }
                    else
                    {
                        leaveData = employeeId == "0" ? FindAllByCondition(x => x.FromDate.Year == year || x.ToDate.Year == year).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Status == leaveType && x.Person.IsActive == status).ToList() :
                                    FindAllByCondition(x => x.FromDate.Year == year || x.ToDate.Year == year).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.Person.EmployeeCode == employeeId && x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Status == leaveType && x.Person.IsActive == status).ToList();
                    }
                }
                else
                {
                    if (leaveType == "All")
                    {
                        leaveData = employeeId == "0" ? FindAllByCondition(x => (x.FromDate.Month == month || x.ToDate.Month == month) && (x.FromDate.Year == year || x.ToDate.Year == year)).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Person.IsActive == status).ToList() :
                                    FindAllByCondition(x => (x.FromDate.Month == month || x.ToDate.Month == month) && (x.FromDate.Year == year || x.ToDate.Year == year)).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.Person.EmployeeCode == employeeId && x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Person.IsActive == status).ToList();
                    }
                    else if (leaveType == "Pending")
                    {
                        leaveData = employeeId == "0" ? FindAllByCondition(x => (x.FromDate.Month == month || x.ToDate.Month == month) && (x.FromDate.Year == year || x.ToDate.Year == year)).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.TenantId == TenantId && x.Person.Location.IsActive == true && (x.Status == leaveType || x.Status == "Requested For Cancel") && x.Person.IsActive == status).ToList() :
                                    FindAllByCondition(x => (x.FromDate.Month == month || x.ToDate.Month == month) && (x.FromDate.Year == year || x.ToDate.Year == year)).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.Person.EmployeeCode == employeeId && x.TenantId == TenantId && x.Person.Location.IsActive == true && (x.Status == leaveType || x.Status == "Requested For Cancel") && x.Person.IsActive == status).ToList();
                    }
                    else if (leaveType == "Approved")
                    {
                        leaveData = employeeId == "0" ? FindAllByCondition(x => (x.FromDate.Month == month || x.ToDate.Month == month) && (x.FromDate.Year == year || x.ToDate.Year == year)).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Status.StartsWith(leaveType) && x.Person.IsActive == status).ToList() :
                                    FindAllByCondition(x => (x.FromDate.Month == month || x.ToDate.Month == month) && (x.FromDate.Year == year || x.ToDate.Year == year)).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.Person.EmployeeCode == employeeId && x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Status.StartsWith(leaveType) && x.Person.IsActive == status).ToList();
                    }
                    else
                    {
                        leaveData = employeeId == "0" ? FindAllByCondition(x => (x.FromDate.Month == month || x.ToDate.Month == month) && (x.FromDate.Year == year || x.ToDate.Year == year)).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Status == leaveType && x.Person.IsActive == status).ToList() :
                                    FindAllByCondition(x => (x.FromDate.Month == month || x.ToDate.Month == month) && (x.FromDate.Year == year || x.ToDate.Year == year)).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.Person.EmployeeCode == employeeId && x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Status == leaveType && x.Person.IsActive == status).ToList();
                    }
                }
            }
            else
            {
                if (month == 0)
                {
                    if (leaveType == "All")
                    {
                        leaveData = employeeId == "0" ? FindAllByCondition(x => x.FromDate.Year == year || x.ToDate.Year == year).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Person.LocationId == locationId && x.Person.IsActive == status).ToList() :
                                    FindAllByCondition(x => x.FromDate.Year == year || x.ToDate.Year == year).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.Person.EmployeeCode == employeeId && x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Person.LocationId == locationId && x.Person.IsActive == status).ToList();
                    }
                    else if (leaveType == "Pending")
                    {
                        leaveData = employeeId == "0" ? FindAllByCondition(x => x.FromDate.Year == year || x.ToDate.Year == year).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Person.LocationId == locationId && (x.Status == leaveType || x.Status == "Requested For Cancel") && x.Person.IsActive == status).ToList() :
                                    FindAllByCondition(x => x.FromDate.Year == year || x.ToDate.Year == year).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.Person.EmployeeCode == employeeId && x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Person.LocationId == locationId && (x.Status == leaveType || x.Status == "Requested For Cancel") && x.Person.IsActive == status).ToList();
                    }
                    else if (leaveType == "Approved")
                    {
                        leaveData = employeeId == "0" ? FindAllByCondition(x => x.FromDate.Year == year || x.ToDate.Year == year).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Person.LocationId == locationId && x.Status.StartsWith(leaveType) && x.Person.IsActive == status).ToList() :
                                    FindAllByCondition(x => x.FromDate.Year == year || x.ToDate.Year == year).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.Person.EmployeeCode == employeeId && x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Person.LocationId == locationId && x.Status.StartsWith(leaveType) && x.Person.IsActive == status).ToList();
                    }
                    else
                    {
                        leaveData = employeeId == "0" ? FindAllByCondition(x => x.FromDate.Year == year || x.ToDate.Year == year).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Person.LocationId == locationId && x.Status == leaveType && x.Person.IsActive == status).ToList() :
                                    FindAllByCondition(x => x.FromDate.Year == year || x.ToDate.Year == year).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.Person.EmployeeCode == employeeId && x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Person.LocationId == locationId && x.Status == leaveType && x.Person.IsActive == status).ToList();
                    }
                }
                else
                {
                    if (leaveType == "All")
                    {
                        leaveData = employeeId == "0" ? FindAllByCondition(x => (x.FromDate.Month == month || x.ToDate.Month == month) && (x.FromDate.Year == year || x.ToDate.Year == year)).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Person.LocationId == locationId && x.Person.IsActive == status).ToList() :
                                    FindAllByCondition(x => (x.FromDate.Month == month || x.ToDate.Month == month) && (x.FromDate.Year == year || x.ToDate.Year == year)).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.Person.EmployeeCode == employeeId && x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Person.LocationId == locationId && x.Person.IsActive == status).ToList();
                    }
                    else if (leaveType == "Pending")
                    {
                        leaveData = employeeId == "0" ? FindAllByCondition(x => (x.FromDate.Month == month || x.ToDate.Month == month) && (x.FromDate.Year == year || x.ToDate.Year == year)).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Person.LocationId == locationId && (x.Status == leaveType || x.Status == "Requested For Cancel") && x.Person.IsActive == status).ToList() :
                                    FindAllByCondition(x => (x.FromDate.Month == month || x.ToDate.Month == month) && (x.FromDate.Year == year || x.ToDate.Year == year)).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.Person.EmployeeCode == employeeId && x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Person.LocationId == locationId && (x.Status == leaveType || x.Status == "Requested For Cancel") && x.Person.IsActive == status).ToList();
                    }
                    else if (leaveType == "Approved")
                    {
                        leaveData = employeeId == "0" ? FindAllByCondition(x => (x.FromDate.Month == month || x.ToDate.Month == month) && (x.FromDate.Year == year || x.ToDate.Year == year)).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Person.LocationId == locationId && x.Status.StartsWith(leaveType) && x.Person.IsActive == status).ToList() :
                                    FindAllByCondition(x => (x.FromDate.Month == month || x.ToDate.Month == month) && (x.FromDate.Year == year || x.ToDate.Year == year)).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.Person.EmployeeCode == employeeId && x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Person.LocationId == locationId && x.Status.StartsWith(leaveType) && x.Person.IsActive == status).ToList();
                    }
                    else
                    {
                        leaveData = employeeId == "0" ? FindAllByCondition(x => (x.FromDate.Month == month || x.ToDate.Month == month) && (x.FromDate.Year == year || x.ToDate.Year == year)).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Person.LocationId == locationId && x.Status == leaveType && x.Person.IsActive == status).ToList() :
                                    FindAllByCondition(x => (x.FromDate.Month == month || x.ToDate.Month == month) && (x.FromDate.Year == year || x.ToDate.Year == year)).Include(x => x.Person).Include(x => x.Person.Role).Include(x => x.Person.Location).Where(x => x.Person.EmployeeCode == employeeId && x.TenantId == TenantId && x.Person.Location.IsActive == true && x.Person.LocationId == locationId && x.Status == leaveType && x.Person.IsActive == status).ToList();
                    }
                }
            }
            int idData = 0;

            foreach (var data in leaveData)
            {
                idData = data.UpdatedBy.GetValueOrDefault();
                LeaveRequestViewModel leave = new LeaveRequestViewModel
                {
                    Id            = data.Id,
                    LocationName  = data.Person.Location.LocationName,
                    EmployeeCode  = data.Person.EmployeeCode,
                    EmployeeName  = data.EmployeeName,
                    EmployeeRole  = data.Person.Role.Name,
                    RequestedDays = data.RequestedDays,
                    FromDate      = data.FromDate,
                    ToDate        = data.ToDate,
                    LeaveType     = data.LeaveType,
                    Available     = data.Available,
                    AppliedDate   = data.AppliedDate,
                    Status        = data.Status,
                    Reason        = string.IsNullOrEmpty(data.Reason) ? "-" : data.Reason,
                    PersonId      = data.Person.Id
                };

                if (idData != 0)
                {
                    leave.ApprovedName = _dbContext.Person.Where(x => x.Id == idData).FirstOrDefault().FullName;
                }
                else
                {
                    leave.ApprovedName = "-";
                }
                leaveDataView.Add(leave);
            }
            return(leaveDataView);
        }