示例#1
0
        // GET: Employee/Leave/Status
        public ActionResult Details()
        {
            try
            {
                var _leaveViewModel = new LeaveViewModel();
                _leaveViewModel.availedLeaveViewModel = new AvailedLeaveViewModel();
                _leaveViewModel.LeaveRequestInfo      = new LeaveRequestInfo();
                _leaveViewModel.CasualLeave           = new LeaveInfo();
                _leaveViewModel.AnnualLeave           = new LeaveInfo();

                var _leaveAllowed = new LeaveAllowedInfo();

                using (LeaveRequestRepository Repo = new LeaveRequestRepository())
                {
                    _leaveViewModel.CasualLeaveRequestInfoList = Repo.GetCasualLeaveRequestListByEmployeeId(CurrentUser.EmployeeInfoId);
                    _leaveViewModel.AnnualLeaveRequestInfoList = Repo.GetAnnualLeaveRequestListByEmployeeId(CurrentUser.EmployeeInfoId);

                    _leaveViewModel.LeaveRequestInfo = Repo.GetLeaveRequestLastRecordByEmployeeId(CurrentUser.EmployeeInfoId);

                    if (_leaveViewModel.LeaveRequestInfo == null)
                    {
                        _leaveViewModel.LeaveRequestInfo = new LeaveRequestInfo();
                    }

                    _leaveViewModel.availedLeaveViewModel.CasualLeaveRequestInfoList = _leaveViewModel.CasualLeaveRequestInfoList;
                    _leaveViewModel.availedLeaveViewModel.AnnualLeaveRequestInfoList = _leaveViewModel.AnnualLeaveRequestInfoList;
                }

                using (LeaveAllowedRepository Repo = new LeaveAllowedRepository())
                {
                    _leaveAllowed = Repo.GetLeaveAllowedByEmployeeId(CurrentUser.EmployeeInfoId);
                }

                _leaveViewModel.CasualLeave.Allowed   = _leaveAllowed.Casual;
                _leaveViewModel.CasualLeave.Availed   = LeavesCounter.GetAvailedLeaves(_leaveViewModel.CasualLeaveRequestInfoList);
                _leaveViewModel.CasualLeave.Remaining = _leaveViewModel.CasualLeave.Allowed - _leaveViewModel.CasualLeave.Availed;

                _leaveViewModel.AnnualLeave.Allowed   = _leaveAllowed.Annual;
                _leaveViewModel.AnnualLeave.Availed   = LeavesCounter.GetAvailedLeaves(_leaveViewModel.AnnualLeaveRequestInfoList);
                _leaveViewModel.AnnualLeave.Remaining = _leaveViewModel.AnnualLeave.Allowed - _leaveViewModel.AnnualLeave.Availed;

                if (_leaveViewModel.CasualLeave.Availed >= _leaveAllowed.Casual)
                {
                    _leaveViewModel.LeaveRequestInfo.IsCasualLeaveAvailed = true;
                }

                if (_leaveViewModel.AnnualLeave.Availed >= _leaveAllowed.Annual)
                {
                    _leaveViewModel.LeaveRequestInfo.IsAnnualLeaveAvailed = true;
                }

                return(View(_leaveViewModel));
            }

            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Leave", "Details")));
            }
        }
示例#2
0
        // GET: Admin/Leave/Manage
        public ActionResult Manage(string id = "")
        {
            try
            {
                ViewBag.EmployeeId = GetEmployeeFullNameList();

                int empId;
                var _leaveViewModel = new LeaveViewModel();
                _leaveViewModel.LeaveRequestInfoList = new List <LeaveRequestInfo>();
                _leaveViewModel.LeaveRequestInfo     = new LeaveRequestInfo();
                _leaveViewModel.CasualLeave          = new LeaveInfo();
                _leaveViewModel.AnnualLeave          = new LeaveInfo();

                var _leaveAllowed = new LeaveAllowedInfo();

                if (!int.TryParse(id, out empId))
                {
                    _leaveViewModel = null;

                    return(View(_leaveViewModel));
                }

                using (LeaveRequestRepository Repo = new LeaveRequestRepository())
                {
                    _leaveViewModel.CasualLeaveRequestInfoList = Repo.GetCasualLeaveRequestListByEmployeeId(empId);
                    _leaveViewModel.AnnualLeaveRequestInfoList = Repo.GetAnnualLeaveRequestListByEmployeeId(empId);

                    _leaveViewModel.LeaveRequestInfoList = Repo.GetLeaveRequestListByEmployeeId(empId);
                    _leaveViewModel.LeaveRequestInfo     = Repo.GetLeaveRequestLastRecordByEmployeeId(empId);
                }

                using (LeaveAllowedRepository Repo = new LeaveAllowedRepository())
                {
                    _leaveAllowed = Repo.GetLeaveAllowedByEmployeeId(empId);
                }

                _leaveViewModel.CasualLeave.Allowed   = _leaveAllowed.Casual;
                _leaveViewModel.CasualLeave.Availed   = LeavesCounter.GetAvailedLeaves(_leaveViewModel.CasualLeaveRequestInfoList);
                _leaveViewModel.CasualLeave.Remaining = _leaveViewModel.CasualLeave.Allowed - _leaveViewModel.CasualLeave.Availed;

                _leaveViewModel.AnnualLeave.Allowed   = _leaveAllowed.Annual;
                _leaveViewModel.AnnualLeave.Availed   = LeavesCounter.GetAvailedLeaves(_leaveViewModel.AnnualLeaveRequestInfoList);
                _leaveViewModel.AnnualLeave.Remaining = _leaveViewModel.AnnualLeave.Allowed - _leaveViewModel.AnnualLeave.Availed;

                _leaveViewModel.EmployeeInfoId = id.ToString();

                return(View(_leaveViewModel));
            }

            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Leave", "Manage")));
            }
        }
示例#3
0
        // GET: Admin/Leave/Reset
        public ActionResult Reset(string id = "")
        {
            try
            {
                int empId;
                var _leavesAllowed = new LeaveAllowedInfo();

                EmployeeInfo _employee = null;

                //if (CurrentUser.Role != "SuperAdmin")
                //{
                //    TempData["Msg"] = AlertMessageProvider.FailureMessage("You don't have permission to access this feature.");

                //    return RedirectToAction("Manage", "Leave");
                //}

                if (!int.TryParse(id, out empId))
                {
                    return(RedirectToAction("Manage", "Leave"));
                }

                using (EmployeeRepository Repo = new EmployeeRepository())
                {
                    _employee = Repo.GetEmployeeInfoById(empId);
                }

                if (_employee == null)
                {
                    return(RedirectToAction("Manage", "Leave"));
                }

                using (LeaveAllowedRepository Repo = new LeaveAllowedRepository())
                {
                    _leavesAllowed = Repo.GetLeaveAllowedByEmployeeId(empId);
                }

                _leavesAllowed.EmployeeFullName = _employee.FirstName + " " + _employee.LastName;

                return(View(_leavesAllowed));
            }

            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Leave", "Delete")));
            }
        }
示例#4
0
        public ActionResult Reset(LeaveAllowedInfo leaveAllowedInfo)
        {
            try
            {
                //if (CurrentUser.Role != "SuperAdmin")
                //{
                //    TempData["Msg"] = AlertMessageProvider.FailureMessage("You don't have permission to access this feature.");

                //    return RedirectToAction("Manage", "Leave");
                //}

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

                    //return RedirectToAction("Reset", "Leave", new { id = leaveAllowedInfo.EmployeeInfoId });
                }

                LeaveAllowedInfo leavesAllowed = null;

                using (LeaveAllowedRepository Repo = new LeaveAllowedRepository())
                {
                    leavesAllowed = Repo.GetLeaveAllowedByEmployeeId(leaveAllowedInfo.EmployeeInfoId);

                    if (leavesAllowed == null)
                    {
                        TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later.");

                        return(RedirectToAction("Manage", "Leave"));
                    }

                    if (leaveAllowedInfo.Casual > 5)
                    {
                        TempData["Msg"] = AlertMessageProvider.FailureMessage("Maximum 15 casual leaves allowed.");

                        return(RedirectToAction("Reset", "Leave", new { id = leaveAllowedInfo.EmployeeInfoId }));
                    }

                    if (leaveAllowedInfo.Annual > 15)
                    {
                        TempData["Msg"] = AlertMessageProvider.FailureMessage("Maximum 30 annual leaves allowed.");

                        return(RedirectToAction("Reset", "Leave", new { id = leaveAllowedInfo.EmployeeInfoId }));
                    }

                    leaveAllowedInfo.Id                  = leavesAllowed.Id;
                    leaveAllowedInfo.ModifiedDate        = DateTime.Now;
                    leaveAllowedInfo.ModifiedByAccountId = CurrentUser.AccountId;

                    Repo.UpdateLeaveAllowed(leaveAllowedInfo);
                }

                TempData["Msg"] = AlertMessageProvider.SuccessMessage("Leave(s) has been reset successfully.");

                return(RedirectToAction("Manage", "Leave", new { id = leaveAllowedInfo.EmployeeInfoId }));
            }

            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Leave", "Update")));
            }
        }
示例#5
0
        public ActionResult ApplyLeaves(LeaveRequestInfo leaveRequestInfo)
        {
            try
            {
                if (leaveRequestInfo.LeaveType != "Casual" && leaveRequestInfo.LeaveType != "Annual" || string.IsNullOrEmpty(leaveRequestInfo.LeaveDate))
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later.");

                    return(RedirectToAction("Status", "Leave"));
                }

                string[] _dateRange = leaveRequestInfo.LeaveDate.Split(new string[] { " - " }, StringSplitOptions.None);
                DateTime _leaveStartDate;
                DateTime _leaveEndDate;
                var      _leaveAllowed = new LeaveAllowedInfo();

                if (!DateTime.TryParse(_dateRange[0], out _leaveStartDate) || !DateTime.TryParse(_dateRange[1], out _leaveEndDate))
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("Invalid leave date, please select valid date.");

                    return(RedirectToAction("Details", "Leave"));
                }

                _leaveStartDate = DateTime.Parse(_dateRange[0]);
                _leaveEndDate   = DateTime.Parse(_dateRange[1]);

                int _totalSelectedLeaves = LeavesCounter.CountLeavesWithoutWeekend(_leaveStartDate, _leaveEndDate);  //(_leaveStartDate - _leaveEndDate).Days + 1;

                if (_leaveStartDate.Date < DateTime.Now.Date)
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("Start date cannot be later than today.");

                    return(RedirectToAction("Details", "Leave"));
                }

                int _monthsDiff = ((_leaveStartDate.Year - DateTime.Now.Year) * 12) + _leaveStartDate.Month - DateTime.Now.Month;

                if (_monthsDiff > 1)
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("You cannot apply for leaves earlier than 1 month.");

                    return(RedirectToAction("Details", "Leave"));
                }

                if (_leaveEndDate.Date < _leaveStartDate.Date)
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("Start date cannot be later than end date.");

                    return(RedirectToAction("Details", "Leave"));
                }

                if (_totalSelectedLeaves == 0)
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("You can't apply for saturday and sunday.");

                    return(RedirectToAction("Details", "Leave"));
                }

                using (LeaveAllowedRepository Repo = new LeaveAllowedRepository())
                {
                    _leaveAllowed = Repo.GetLeaveAllowedByEmployeeId(CurrentUser.EmployeeInfoId);
                }

                using (LeaveRequestRepository Repo = new LeaveRequestRepository())
                {
                    LeaveRequestInfo _leaveRequest = null;
                    _leaveRequest = Repo.GetLeaveRequestLastRecordByEmployeeId(CurrentUser.EmployeeInfoId);

                    if (_leaveRequest != null)
                    {
                        if (_leaveRequest.EndDate.Date == _leaveStartDate.Date)
                        {
                            TempData["Msg"] = AlertMessageProvider.FailureMessage("You have already a leave today.");

                            return(RedirectToAction("Details", "Leave"));
                        }

                        if (_leaveRequest.Status == "Pending" || _leaveRequest.Status == "Approved" && _leaveRequest.EndDate.Date > DateTime.Now.Date)
                        {
                            TempData["Msg"] = AlertMessageProvider.FailureMessage("You have already applied for leaves.");

                            return(RedirectToAction("Details", "Leave"));
                        }
                    }

                    if (leaveRequestInfo.LeaveType == "Casual")
                    {
                        var _leavesList = Repo.GetCasualLeaveRequestListByEmployeeId(CurrentUser.EmployeeInfoId);
                        int _totalAvailedCasualLeaves = LeavesCounter.GetRemainingLeaves(_leavesList, _leaveAllowed.Casual);

                        if (_totalSelectedLeaves > _totalAvailedCasualLeaves)
                        {
                            TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select upto remaining casual leaves.");

                            return(RedirectToAction("Details", "Leave"));
                        }
                    }
                    else if (leaveRequestInfo.LeaveType == "Annual")
                    {
                        var _leavesList = Repo.GetAnnualLeaveRequestListByEmployeeId(CurrentUser.EmployeeInfoId);
                        int _totalAvailedAnnualLeaves = LeavesCounter.GetRemainingLeaves(_leavesList, _leaveAllowed.Annual);

                        if (_totalSelectedLeaves > _totalAvailedAnnualLeaves)
                        {
                            TempData["Msg"] = AlertMessageProvider.FailureMessage("Please select upto remaining annual leaves.");

                            return(RedirectToAction("Details", "Leave"));
                        }
                    }
                }

                leaveRequestInfo.RequestDate      = DateTime.Now;
                leaveRequestInfo.StartDate        = _leaveStartDate;
                leaveRequestInfo.EndDate          = _leaveEndDate;
                leaveRequestInfo.Status           = "Pending";
                leaveRequestInfo.Remark           = "";
                leaveRequestInfo.IsCreatedByAdmin = false;
                leaveRequestInfo.EmployeeInfoId   = CurrentUser.EmployeeInfoId;

                string Subject = "Leave(s) Request";
                string Body    = "<b>Employee: </b>" + CurrentUser.Name + ".<br/>" +
                                 "<b>Total Leaves: </b>" + _totalSelectedLeaves + ".<br/>" +
                                 "<b>Leave Date: </b>" + leaveRequestInfo.LeaveDate + ".<br/><br/>" +
                                 "<b>Leave Reason: </b><br/>" + leaveRequestInfo.Reason + "<br/><br/>" +
                                 "Thanks.<br/>";

                var status = EmailSender.Send(Subject, Body);
                if (status)
                {
                    using (LeaveRequestRepository Repo = new LeaveRequestRepository())
                    {
                        Repo.SaveLeaveRequest(leaveRequestInfo);
                    }

                    TempData["Msg"] = AlertMessageProvider.SuccessMessage("You have applied for leaves successfully, please wait for approval.");
                }
                else
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("Email sending failed! please try again later.");
                }

                return(RedirectToAction("Details", "Leave"));
            }

            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Leave", "ApplyLeaves")));
            }
        }