public void SaveLeaveAllowed(LeaveAllowedInfo leaveAllowedInfo)
        {
            Data.LeaveAllowed leaveAllowed = ConvertToDb(leaveAllowedInfo);

            _context.LeaveAlloweds.Add(leaveAllowed);
            _context.SaveChanges();
        }
Example #2
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")));
            }
        }
Example #3
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")));
            }
        }
 public Data.LeaveAllowed ConvertToDb(LeaveAllowedInfo leaveAllowedInfo)
 {
     return(new Data.LeaveAllowed
     {
         Id = leaveAllowedInfo.Id,
         Casual = leaveAllowedInfo.Casual,
         Annual = leaveAllowedInfo.Annual,
         EmployeeInfoId = leaveAllowedInfo.EmployeeInfoId,
         CreatedDate = leaveAllowedInfo.CreatedDate,
         CreatedByAccountId = leaveAllowedInfo.CreatedByAccountId,
         ModifiedDate = leaveAllowedInfo.ModifiedDate,
         ModifiedByAccountId = leaveAllowedInfo.ModifiedByAccountId,
     });
 }
Example #5
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")));
            }
        }
        public void UpdateLeaveAllowed(LeaveAllowedInfo leaveAllowedInfo)
        {
            Data.LeaveAllowed leaveAllowed = _context.LeaveAlloweds.Find(leaveAllowedInfo.Id);

            if (leaveAllowed != null)
            {
                leaveAllowed.Casual              = leaveAllowedInfo.Casual;
                leaveAllowed.Annual              = leaveAllowedInfo.Annual;
                leaveAllowed.ModifiedDate        = leaveAllowedInfo.ModifiedDate;
                leaveAllowed.ModifiedByAccountId = leaveAllowedInfo.ModifiedByAccountId;

                _context.SaveChanges();
            }
            else
            {
                throw new ArgumentNullException();
            }
        }
Example #7
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")));
            }
        }
Example #8
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")));
            }
        }
Example #9
0
        public ActionResult Create(AccountInfo accountInfo)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var _employeeInfo = new Model.EmployeeInfo();
                    _employeeInfo.CreatedByAccountId = CurrentUser.AccountId;
                    _employeeInfo.CreatedDate        = DateTime.Now;

                    int employeeInfoId;
                    int accountId;

                    string saltValue = RandomPassword.Generate(18, 20);
                    string password  = RijndaelCrypt.EncryptPassword(RandomPassword.Generate(), saltValue);

                    accountInfo.CompanyEmail     = accountInfo.CompanyEmail.ToLower();
                    accountInfo.PasswordHash     = password;
                    accountInfo.Salt             = saltValue;
                    accountInfo.LastLoginDate    = DateTime.Now;
                    accountInfo.LastLoginIp      = "";
                    accountInfo.IsActive         = true;
                    accountInfo.IsFirstTimeLogin = true;

                    using (var transaction = new System.Transactions.TransactionScope())
                    {
                        using (AccountRepository Repo = new AccountRepository())
                        {
                            if (Repo.IsEmailExist(accountInfo.CompanyEmail) == true)
                            {
                                TempData["Msg"] = AlertMessageProvider.FailureMessage("Email already exist.");

                                return(View());
                            }

                            int roleId = Repo.GetRoleIdByName("Anonymous");
                            accountInfo.RoleId = roleId;

                            accountId = Repo.CreateAccount(accountInfo);
                        }

                        using (AccountCheckListRepository Repo = new AccountCheckListRepository())
                        {
                            var _accountCheckList = new AccountCheckListInfo(accountId);

                            Repo.SaveAccountCheckList(_accountCheckList);
                        }

                        using (EmployeeRepository Repo = new EmployeeRepository())
                        {
                            _employeeInfo.AccountId = accountId;

                            employeeInfoId = Repo.SaveEmployeeInfo(_employeeInfo);
                        }

                        using (LeaveAllowedRepository Repo = new LeaveAllowedRepository())
                        {
                            LeaveAllowedInfo _leaveAllowed = new LeaveAllowedInfo(0, 0, employeeInfoId, CurrentUser.AccountId);

                            Repo.SaveLeaveAllowed(_leaveAllowed);
                        }

                        using (SalaryRepository Repo = new SalaryRepository())
                        {
                            var _salaryInfo = new SalaryInfo(CurrentUser.AccountId, employeeInfoId);

                            Repo.SaveSalary(_salaryInfo);
                        }

                        using (FamilyMemberRepository Repo = new FamilyMemberRepository())
                        {
                            var _familyMember = new FamilyMemberInfo
                            {
                                Name           = "Self",
                                Relation       = "Selef",
                                EmployeeInfoId = employeeInfoId
                            };

                            Repo.SaveFamilyMember(_familyMember);
                        }

                        transaction.Complete();
                    }

                    List <string> To = new List <string>()
                    {
                        accountInfo.CompanyEmail
                    };
                    string Subject  = "LPS Online Account Information";
                    var    LoginUrl = Url.Action("Login", "Auth", new { Area = "" }, protocol: Request.Url.Scheme);

                    string Body = "Dear Employee, <br/><br/>" +
                                  "Your account has been created.<br/>" +
                                  "Please ensure to save the username and password written below:<br/><br/>" +
                                  "Username: &nbsp; <b>" + accountInfo.CompanyEmail + "</b><br/>" +
                                  "Password: &nbsp; <b>" + RijndaelCrypt.DecryptPassword(accountInfo.PasswordHash, accountInfo.Salt) + "</b><br/><br/>" +
                                  "<a href='" + LoginUrl + "' target='_blank'>" + LoginUrl + "</a><br/>" +
                                  "You can login to your account to use LPS online services.<br/><br/>" +
                                  "Thanks,<br/>" +
                                  "<b>Logic Powered Solutions</b>";

                    bool result = EmailSender.Send(Subject, Body, To);

                    if (result)
                    {
                        TempData["Msg"] = AlertMessageProvider.SuccessMessage("Account created, email has been sent to employee successfully.");
                    }
                    else
                    {
                        TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong! email not sent, please try again later.");
                    }

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

                return(View());
            }

            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Account", "Create")));
            }
        }