// Check session in page initia stage
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            try
            {
                if ((Session["AuthenticatedUser"] != null))// || (Session["loanStep"] != null)
                 {    
                    userData = ((User)Session["AuthenticatedUser"]);
                    if (Session["loanStep"] != null)
                    {
                        
                        loanData = ((LoanSetupStep)Session["loanStep"]);
                        Session["companyStep"] = 5;

                        if(loanData.loanId > 0)
                        {
                            loanstep = loanData.stepId;
                            CurtailmentAccess curtailmentAccess = new CurtailmentAccess();

                           
                            _loan = curtailmentAccess.GetLoanDetailsByLoanId(loanData.loanId);
                            
                            Session["isInterest"] = _loan.isInterestCalculate;
                        }
                        else if (loanData.loanId == 0)
                        {
                            loanstep = 1;
                            //CurtailmentAccess curtailmentAccess = new CurtailmentAccess();


                            // _loan = curtailmentAccess.GetLoanDetailsByLoanId(loanData.loanId);

                            // Session["isInterest"] = _loan.isInterestCalculate;
                        }
                    }
                }
                else
                {
                    if (HttpContext.Request.IsAjaxRequest())
                    {
                        filterContext.Result = new HttpStatusCodeResult(404, "Due to inactivity your session has timed out, please log in again.");
                    }
                    else
                    {

                        filterContext.Result = new RedirectResult("/Login/UserLogin?lbl=Due to inactivity your session has timed out, please log in again.");
                    }
                }
            }
            catch
            {
                filterContext.Result = new RedirectResult("~/Exceptions/Index");
            }
        }
        public ActionResult Step10(string lbl)
        {
            CurtailmentModel curtailment = new CurtailmentModel();

            int userId = userData.UserId;
            if (userData.RoleId >= 3)
            {
                return RedirectToAction("UserLogin", "Login", new { lbl = "You are not Allowed." });
            }

            //check user step is valid for this step
            StepAccess sa = new StepAccess();
            if (loanData.stepId == 5)
            {
                ViewBag.LoanId = 0;
                if (lbl == "Details added successfully")
                {
                    ViewBag.SuccessMsg = "Loan setup is completed";
                    Session["loanStep"] = null;
                    if (TempData["LoanId"] != null && (int)TempData["LoanId"] > 0) {
                        ViewBag.LoanId = (int)TempData["LoanId"];
                    }
                   
                    if (HttpContext.Request.IsAjaxRequest())
                    {
                        ViewBag.AjaxRequest = 1;
                        return PartialView(curtailment);
                    }
                    return View(curtailment);
                }

                int branchId = loanData.BranchId;

                LoanSetupAccess la = new LoanSetupAccess();
                int loanId = loanData.loanId;
                CurtailmentAccess curAccess = new CurtailmentAccess();
                _loan = curAccess.GetLoanDetailsByLoanId(loanId);
                _loan.loanId = loanId;
                
                curtailment.AdvancePt = _loan.advancePercentage;
                curtailment.RemainingPercentage = curtailment.AdvancePt;

                curtailment.InfoModel = new List<Curtailment>();

                var curtailments = curAccess.retreiveCurtailmentByLoanId(loanId);

                int payPercentage = _loan.advancePercentage;
                int? totalPercentage = 0;

                int curId = 0;
                if (curtailments != null && curtailments.Count > 0)
                {
                    for (int i = 0; i < curtailments.Count; i++)
                    {
                        curId++;
                        totalPercentage += curtailments[i].Percentage;
                        curtailment.InfoModel.Add(new Curtailment { CurtailmentId = curId, TimePeriod = curtailments[i].TimePeriod, Percentage = curtailments[i].Percentage });
                    }
                    curtailment.LoanStatus = _loan.LoanStatus ? "Yes" : "No";

                    curtailment.CalculationBase = _loan.CurtailmentCalculationBase == "a" ? "Advance" : "Full payment";
                    curtailment.DueDate = _loan.CurtailmentDueDate;
                    curtailment.AutoRemindEmail = _loan.CurtailmentAutoRemindEmail;
                    curtailment.EmailRemindPeriod = _loan.CurtailmentEmailRemindPeriod;
                }

                ViewBag.CalMode = "Full Payment";
                curtailment.RemainingPercentage = payPercentage - totalPercentage;

                if (curtailment.RemainingPercentage > 0)
                    curtailment.InfoModel.Add(new Curtailment { CurtailmentId = curId + 1 });
                ViewData["objmodel"] = curtailment;

                if (HttpContext.Request.IsAjaxRequest())
                {
                    ViewBag.AjaxRequest = 1;
                    return PartialView(curtailment);
                }
                else
                {

                    return View(curtailment);
                }
            }
            return RedirectToAction("UserLogin", "Login", new { lbl = "Due to inactivity your session has timed out, please log in again." });
        }