Esempio n. 1
0
        public IActionResult ApplyLeave(Leave leave)
        {
            bool isSuccess = false;

            try
            {
                int id = Convert.ToInt32(HttpContext.Session.GetInt32("id"));
                ViewBag.login = 1;
                leave.EmpID   = id;
                leave.Count   = leave.EndDate.Subtract(leave.StartDate).Days;
                if (leave.Count >= 0)
                {
                    int weekendCountCheck = CheckIfWeekendsAreThere(leave);
                    leave.Count = (leave.Count - weekendCountCheck) + 1;
                }

                if (leave.Count == 0)
                {
                    ViewBag.holidays = 1;
                    return(View());
                }
                if (leave.Count < 0)
                {
                    ViewBag.errorEntry = 1;
                    return(View());
                }

                else
                {
                    LeaveService leaveService = new LeaveService();
                    int          returnValue  = leaveService.AddLeaveDetails(leave);
                    if (returnValue == 1)
                    {
                        return(RedirectToAction("Index", "Employee"));
                    }
                    else
                    {
                        ViewBag.IsSuccess = isSuccess;
                    }
                }

                return(View());
            }
            catch (Exception e)
            {
                ErrorViewModel errorView = new ErrorViewModel();
                errorView.Message = "Error Occured while Applying Leave";
                errorView.Reason  = e.Message;
                return(RedirectToAction("Error", "ErrorHandling", errorView));
            }
        }
Esempio n. 2
0
 public IActionResult ApplyLeave(int id, Leave leave)
 {
     try
     {
         leave.EmpID = id;
         leave.count = leave.endDate.Subtract(leave.startDate).Days + 1;
         leaveService.AddLeaveDetails(leave);
         return(RedirectToAction("Index", "Employee", new { id = leave.EmpID }));
     }
     catch (Exception e)
     {
         ErrorViewModel errorView = new ErrorViewModel();
         errorView.Message = "Error Occured while Applying Leave";
         errorView.Reason  = e.Message;
         return(RedirectToAction("Error", "ErrorHandling", errorView));
     }
 }