private AdvanceUnit GetAdvanceUnitList(int loanId)
        {
            UnitAccess         unitAccess = new UnitAccess();
            List <Models.Unit> unitList   = new List <Models.Unit>();

            unitList = unitAccess.GetNotAdvancedUnitDetailsByLoanId(loanId);
            List <Models.Unit> unitList2 = new List <Models.Unit>();
            AdvanceUnit        unitList1 = new AdvanceUnit();

            unitList1.NotAdvanced = unitList;

            unitList1.Search      = unitList2;
            unitList1.AdvanceDate = DateTime.Now;
            return(unitList1);
        }
        private AdvanceUnit GetAdvanceUnitList(int loanId)
        {
            UnitAccess unitAccess = new UnitAccess();
            List<Models.Unit> unitList = new List<Models.Unit>();
            unitList = unitAccess.GetNotAdvancedUnitDetailsByLoanId(loanId);
            List<Models.Unit> unitList2 = new List<Models.Unit>();
            AdvanceUnit unitList1 = new AdvanceUnit();
            unitList1.NotAdvanced = unitList;

            unitList1.Search = unitList2;
            unitList1.AdvanceDate = DateTime.Now;
            return unitList1;
        }
        /// <summary>
        /// Frontend page: Advance Unit
        /// Title: Get loan details and not advanced unit details from database and return to view
        /// Designed: Nadeeka
        /// User story:
        /// Developed: Nadeeka
        /// Date created: 02/24/2016
        /// </summary>
        /// <param name="model"></param>
        /// <returns>Return partial view</returns>
        public ActionResult Advance()
        {
            int flag = -1;
            //assign logged user id to variable
            int    userId = userData.UserId;
            string loanCode;

            try
            {
                //convert session to string variable
                loanCode = Session["loanCode"].ToString();
            }
            catch (Exception)
            {
                //if exception occured return to login page
                return(RedirectToAction("UserLogin", "Login"));
            }
            BranchAccess branch = new BranchAccess();
            //retrieve company type for given user id
            int companyType = branch.getCompanyTypeByUserId(userId);

            //check company type 1-Lender
            if (companyType == 1)
            {
                ViewBag.isLender = true;
            }
            //company type 2 - Dealer
            else
            {
                ViewBag.isLender = false;
            }

            ViewBag.unitClickId = "";
            LoanSetupStep1 loanDetails = new LoanSetupStep1();

            //retrieve loan delails for given loan code
            loanDetails = (new LoanSetupAccess()).GetLoanDetailsByLoanCode(loanCode);
            //check logged user role is user
            if (userData.RoleId == 3)
            {
                //check Session["CurrentLoanRights"] is null or empty
                if (Session["CurrentLoanRights"] == null || Session["CurrentLoanRights"].ToString() == "")
                {
                    return(RedirectToAction("UserDetails", "UserManagement"));
                }
                else
                {
                    var    checkPermission = false;
                    string rgts            = "";
                    //convert Session["CurrentLoanRights"] to string variable
                    rgts = (string)Session["CurrentLoanRights"];
                    string[] rgtList = null;
                    //check right string is not empty
                    if (rgts != "")
                    {
                        //split string
                        rgtList = rgts.Split(',');
                    }
                    //check right list is not null
                    if (rgtList != null)
                    {
                        foreach (var x in rgtList)
                        {
                            //check relevant right for Advance Unit page contains in the user right list
                            if (x == "U01")
                            {
                                checkPermission = true;
                            }
                        }
                        //check permission value is false
                        if (checkPermission == false)
                        {
                            //return to dashboard
                            return(RedirectToAction("UserDetails", "UserManagement"));
                        }
                    }
                    else
                    {
                        //return to dashboard
                        return(RedirectToAction("UserDetails", "UserManagement"));
                    }
                }
            }
            //check logged user is dealer user
            else if (userData.RoleId == 4)
            {
                //return to dashboard
                return(RedirectToAction("UserDetails", "UserManagement"));
            }
            ViewBag.loanDetails = loanDetails;
            Models.Unit unit = new Models.Unit();
            //get units which need to advance for given loan id
            AdvanceUnit advanceUnit = this.GetAdvanceUnitList(loanDetails.loanId);

            //assign loan id to session object
            Session["advUnitloanId"] = loanDetails.loanId;
            //assign not advanced unit list to session object
            Session["notAdvancedList"] = advanceUnit.NotAdvanced;
            ViewBag.advanceList        = advanceUnit.NotAdvanced;
            //check update result of Advance Unit page
            if ((TempData["updateReslt"] != null) && (TempData["updateReslt"].ToString() != ""))
            {
                //convert result to integer
                flag = int.Parse(TempData["updateReslt"].ToString());
            }
            //check result value is 1
            if (flag == 1)
            {
                //flag 1 - success
                ViewBag.Msg = "Success";
            }
            else if (flag == 0)
            {
                //flag 0 - error
                ViewBag.Msg = "Error";
            }
            else if (flag == 2)
            {
                //flag 2 - Advance amount error
                ViewBag.Msg = "Advance amount error";
            }
            else if (flag == 3)
            {
                //flag 3 - Advance error
                ViewBag.Msg = "Advance Error";
            }

            //return advance unit list to view
            return(View(advanceUnit));
        }