Exemple #1
0
        public ActionResult EmployeeLeaveApply(EmployeeLeaveApplyVM viewModel)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    Entities.EmployeeLeaveTransaction entity = new Entities.EmployeeLeaveTransaction();
                    entity.EmployeeId    = viewModel.EmployeeId;
                    entity.LeaveFromDate = viewModel.LeaveFromDate;
                    entity.LeaveToDate   = viewModel.LeaveToDate;
                    entity.LeaveType     = viewModel.LeaveType;

                    entity.Remark = viewModel.Remark == null ? string.Empty : viewModel.Remark;

                    decimal leaveDays = (decimal)(entity.LeaveToDate - entity.LeaveFromDate).TotalDays;
                    if (leaveDays < 0)
                    {
                        TempData["Error"] = "Select valid from date - to date.";
                        // return View(viewModel);
                        return(RedirectToAction("EmployeeLeaveApply"));
                    }
                    entity.LeavesInDays = leaveDays + 1;

                    entity.BalanceLeaves = viewModel.BalanceLeaves - entity.LeavesInDays;


                    EmployeeBAL balObject = new EmployeeBAL();
                    balObject.leaveApply(entity);
                    return(RedirectToAction("EmployeeLeaveApply"));
                }
                else
                {
                    return(View(viewModel));
                }
            }
            catch
            {
                return(View(viewModel));
            }
        }