public int UnitListPay(List<UnitPayOffModel> payOffModelList, DateTime payDate, string titleReturn)
        {
            if (Session["PayOffUnitloanId"] == null)
            {
                return -1;
            }
            
            var loanId = (int) Session["PayOffUnitloanId"];
            try
            {
                XElement xEle = new XElement("Units",
                    from unit in payOffModelList
                    select new XElement("Unit",
                        new XElement("LoanId", loanId),
                        new XElement("UnitId", unit.UnitId),
                        new XElement("Balance", unit.Balance)
                        ));
                string xmlDoc = xEle.ToString();

                int titleStatus = 0;

                if (userData.CompanyType == 1)
                    titleStatus = titleReturn == "Yes" ? 2 : 4;
                else if (userData.CompanyType == 2)
                    titleStatus = titleReturn == "Yes" ? 3 : 4;

                var result = (new CurtailmentAccess()).PayOffUnits(xmlDoc, payDate, titleStatus);

                if(result == 1)
                {
                    //if mention advance fee, then insert in to fee table - asanka
                    UnitAccess unitAccess = new UnitAccess();
                   

                    if ((Session["loanDashboard"] != null) || (Session["oneLoanDashboard"] != null))
                    {
                        
                        Loan loanObj;
                        if (Session["loanDashboard"] != null)
                        {
                            loanObj = (Loan)Session["loanDashboard"];
                        }
                        else
                        {
                            loanObj = (Loan)Session["oneLoanDashboard"];
                        }

                        if (loanObj.AdvanceFee == 1)
                        {
                            //check advance amount and other details      
                            foreach (var payoff in payOffModelList)
                            {
                                unitAccess.insertFreeDetailsForPayOffPage(payoff, payDate,userData.UserId);
                            }
                         }
                    }


                    List<string> IDNumbers = new List<string>();

                    foreach (var payoff in payOffModelList)
                    {
                        IDNumbers.Add(payoff.IdentificationNumber);
                       

                    }

                    //insert to log 
                    Log log = new Log(userData.UserId, userData.Company_Id, userData.BranchId, payOffModelList[0].LoanId, "Pay Off", "Pay Off unit(s) : " + string.Join(",", IDNumbers) + ", Pay Date : " + payDate.ToString("dd/MM/yyyy"), DateTime.Now);

                    int islog = (new LogAccess()).InsertLog(log);
                }

                TempData["message"] = result;
                
                return result;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }