/*

         Frontend page: Fee Page
         Title: get fees by selected date
         Designed: Nadeeka
         User story:
         Developed: Nadeeka
         Date created: 4/25/2016

      */
        
        public ActionResult SearchFee(string identificationNumber, string year, string make, string vehicleModel, FeesModel CurtailmentList)
        {
            List<Fees> SearchList = new List<Fees>();

            // if fee list exists on session
            if (Session["feeList"] != null)
            {
                List<Fees> feeModel = (List<Fees>)Session["feeList"];

                // if atleast one searching criteria matches -- do search
                if (((!string.IsNullOrEmpty(identificationNumber)) || (!string.IsNullOrEmpty(year)) || (!string.IsNullOrEmpty(make)) || (!string.IsNullOrEmpty(vehicleModel))))
                {
                    //search through list of elements
                    Search sc = new Search();

                    SearchList = sc.GetSearchFeeList(feeModel, identificationNumber.Trim().ToLower(), year.Trim().ToLower(), make.Trim().ToLower(), vehicleModel.Trim().ToLower()); // take filtered elements
                     // pass the list to view
                    return PartialView(SearchList);
                }

                // if no searching criteria matched -- retunt empty list
                else
                {

                    return PartialView(SearchList);
                }
            }

            // if fee list not exist on session -- return empty list
            else
            {

                return PartialView(SearchList);
            }
        }
        /// <summary>
        /// Frontend page: Advance Unit(Search section)
        /// Title: get unit list which match with given search parameters
        /// Designed: Piyumi Perera
        /// User story:
        /// Developed: Piyumi Perera
        /// Date created: 02/27/2016
        /// </summary>
        /// <param name="identificationNumber"></param>
        /// <param name="year"></param>
        /// <param name="make"></param>
        /// <param name="vehicleModel"></param>
        /// <returns></returns>
        public ActionResult SearchUnit(string identificationNumber, string year, string make, string vehicleModel)
        {
            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", new { lbl = "Due to inactivity your session has timed out, please log in again." });
            }
            //get loan details for given loan code
            LoanSetupStep1 loanDetails = (new LoanSetupAccess()).GetLoanDetailsByLoanCode(loanCode);
            

            ViewBag.loanDetails = loanDetails;
            //convert Session["notAdvancedList"] to list object
            List<Models.Unit> unitList = (List<Models.Unit>)Session["notAdvancedList"];
            Models.AdvanceUnit unitListMain = new Models.AdvanceUnit();
            unitListMain.NotAdvanced = new List<Models.Unit>();
            //check atleast one parameter is not null or empty
            if (((!string.IsNullOrEmpty(identificationNumber)) || (!string.IsNullOrEmpty(year)) || (!string.IsNullOrEmpty(make)) || (!string.IsNullOrEmpty(vehicleModel))))
            {
                //search through list elements
                Search sc = new Search();
                //get result list of search
                unitListMain.Search = sc.GetSearchResultsList(unitList, identificationNumber.Trim().ToLower(), year.Trim().ToLower(), make.Trim().ToLower(), vehicleModel.Trim().ToLower());
                //return result list in to partial view
                return PartialView(unitListMain);
            }
            else
            {
                //create empty list if all search parameters are null or empty
                unitListMain.Search = new List<Models.Unit>();
                //return list to partial view
                return PartialView(unitListMain);
            }
        }
        /// <summary>
        /// CreatedBy:kasun
        /// CreatedDate:2016/3/21
        /// Search for payoff units
        /// </summary>
        /// <param name="identificationNumber"></param>
        /// <param name="year"></param>
        /// <param name="make"></param>
        /// <param name="vehicleModel"></param>
        /// <returns></returns>
        public ActionResult SearchUnit(string identificationNumber, string year, string make, string vehicleModel)
        {
            string loanCode;
            try
            {
                loanCode = Session["loanCode"].ToString();
            }
            catch (Exception)
            {
                return RedirectToAction("UserLogin", "Login", new { lbl = "Due to inactivity your session has timed out, please log in again." });
            }

            LoanSetupStep1 loanDetails = (new LoanSetupAccess()).GetLoanDetailsByLoanCode(loanCode);


            ViewBag.loanDetails = loanDetails;
            List<UnitPayOffModel> unitList = (List<UnitPayOffModel>)Session["payoffList"];

            UnitPayOffViewModel unitListMain = new UnitPayOffViewModel();
            
            unitListMain.UnitPayOffList = new List<UnitPayOffModel>();
            if (((!string.IsNullOrEmpty(identificationNumber)) || (!string.IsNullOrEmpty(year)) || (!string.IsNullOrEmpty(make)) || (!string.IsNullOrEmpty(vehicleModel))))
            {
                //search through list elements
                Search sc = new Search();

                unitListMain.SearchList = sc.GetSearchPayOffList(unitList, identificationNumber.Trim().ToLower(), year.Trim().ToLower(), make.Trim().ToLower(), vehicleModel.Trim().ToLower());

                return PartialView(unitListMain);
            }
            unitListMain.SearchList = new List<UnitPayOffModel>();
            return PartialView(unitListMain);
        }
        /*

   Frontend page: Curtailment Page
   Title: Searching curtailment details on curtailment list
   Designed: Irfan Mam
   User story: 
   Developed: Irfan MAM
   Date created: 3/18/2016

*/ 
        public ActionResult SearchCurtailment(string identificationNumber, string year, string make, string vehicleModel , CurtailmentScheduleModel CurtailmentList)
        {
            List<CurtailmentShedule> SearchList = new List<CurtailmentShedule>();
            
            // if atleast one arg has the value, do search
            if (((!string.IsNullOrEmpty(identificationNumber)) || (!string.IsNullOrEmpty(year)) || (!string.IsNullOrEmpty(make)) || (!string.IsNullOrEmpty(vehicleModel))))
            {
                
                Search sc = new Search();  // search object

                //search through list of elements
                SearchList = sc.GetSearchCurtailmentList(CurtailmentList, identificationNumber.Trim().ToLower(), year.Trim().ToLower(), make.Trim().ToLower(), vehicleModel.Trim().ToLower() );


                // return the partial page of searched elements
                return PartialView(SearchList);
            }
            else
            {
                // return the partial page of empty elements
                return PartialView(SearchList);
            }
        }