Пример #1
0
        public IActionResult CalculateSalary(DetailsViewModel model)
        {
            if (StaticCache.User == null)
            {
                AddNotification(NotificationViewModel.GetWarning("Page Not Accessable", $"Login to access page"));
                return(RedirectToAction("Index", "Home"));
            }



            if (ModelState.IsValid)
            {
                var request = new ComputeSalaryRequest
                {
                    Month      = model.Month,
                    EmployeeId = model.EmployeeId,
                    DaysAbsent = model.DaysAbsence,
                    DaysWorked = model.DaysWorked
                };

                var res = _employeeManager.CalculateSalary(request);
                if (res.IsSuccess)
                {
                    StaticCache.Employees = _employeeManager.GetAll().Take(20);

                    TempData["MsgSuccess"] = $"Employee Salary for the month of {model.Month} is {res.Data.Salary}";
                    TempData["MsgError"]   = null;

                    return(RedirectToAction(nameof(Details), new { employeeId = model.EmployeeId }));
                }
                else
                {
                    TempData["MsgError"]   = $"{res.Message ?? "Unable to Compute Salary at the moment"}";
                    TempData["MsgSuccess"] = null;

                    return(RedirectToAction(nameof(Details), new { employeeId = model.EmployeeId }));
                }
            }

            TempData["MsgError"]   = $"Unable to Compute Salary at the moment";
            TempData["MsgSuccess"] = null;

            return(RedirectToAction(nameof(Details), new { employeeId = model.EmployeeId }));
        }