public ActionResult EditPartnerCompanyAtDashboard(PartnerCompany partnerCompany)
 {
     //check user is super admin or admin
     if ((userData.RoleId == 1) || (userData.RoleId == 2))
     {
         //check object is not null
         if (partnerCompany != null)
         {
             //assign logged user id to created by property
             partnerCompany.CreatedBy = userData.UserId;
             //assign logged user's company id to registered company id property
             partnerCompany.RegCompanyId = userData.Company_Id;
             //set zip code
             partnerCompany.Zip = partnerCompany.ZipPre;
             if (partnerCompany.Extension != null)
                 partnerCompany.Zip += "-" + partnerCompany.Extension;
             //check result of update partner company is 1
             if ( (new CompanyAccess()).UpdatePartnerCompany(partnerCompany) == 1)
             {
                 TempData["partnerEditReslt"] = 1;
                
             }
             else
             {
                 TempData["partnerEditReslt"] = 0;
             }
             //return to edit partner company page
             return RedirectToAction("EditPartnerCompanyAtDashboard");
         }
         else
         {
             //if object is null return to login page
             return new HttpStatusCodeResult(404);
         }
     }
     else
     {
         //if user is not super admin or admin return to login page
         return new HttpStatusCodeResult(404);
     }
    
 }
        /// <summary>
        /// Frontend page: Edit Partner Company
        /// Title: create view of Edit Partner Company
        /// Designed : Piyumi Perera
        /// User story:
        /// Developed: Piyumi Perera
        /// Date created: 5/4/2016
        /// </summary>
        /// <returns></returns>
        public ActionResult EditPartnerCompanyAtDashboard()
        {
            //check user is super admin or admin
            if ((userData.RoleId == 1) || (userData.RoleId == 2))
            {
                CompanyAccess ca = new CompanyAccess();
                //get all states
                List<State> stateList = ca.GetAllStates();
                ViewBag.StateId = new SelectList(stateList, "StateId", "StateName");
                PartnerCompany pc = new PartnerCompany();
                //get all non registered companies by registered company id
                pc.PartnerCompanyList = ca.GetNonRegCompanyDetailsByRegCompanyId2(userData.Company_Id);
                //check partner company list is null
                if (pc.PartnerCompanyList == null)
                {
                    //create empty partner company list
                    pc.PartnerCompanyList =  new List<PartnerCompany>();
                }
                //get company type by user id
                int comType = (new BranchAccess()).getCompanyTypeByUserId(userData.UserId);
                //company type 1(lender) - partner company type 2(dealer)
                //company type 2(dealer) - partner company type 1(lender)
                ViewBag.ThisCompanyType = (comType == 1) ? "Dealer" : "Lender";
                //check result of update partner company is null and value is 1
                if (TempData["partnerEditReslt"] != null && int.Parse(TempData["partnerEditReslt"].ToString()) == 1)
                {
                    //result 1 - success
                    ViewBag.SuccessMsg = "Partner Company Updated Successfully";
                }
                //check result of update partner company is null and value is 0
                else if (TempData["partnerEditReslt"] != null && int.Parse(TempData["partnerEditReslt"].ToString()) == 0)
                {
                    //result 0 - failure
                    ViewBag.ErrorMsg = "Failed to update partner company";
                }
                //return object to view
                return View(pc);
            }
            else
            {
                //if user is not super admin or admin return to login page
                return new HttpStatusCodeResult(404);
            }

        }
        /// <summary>
        /// CreatedBy : Piyumi
        /// CreatedDate: 05/04/2016
        /// 
        /// Insert company in setup process 
        /// </summary>
        /// <param name="company"></param>
        /// <returns></returns>
        public int InsertNonRegisteredCompanyAtDashboard(PartnerCompany company)
        {
            DataHandler dataHandler = new DataHandler();
            List<object[]> paramertList = new List<object[]>();
            paramertList.Add(new object[] { "@company_name", company.CompanyName.Trim() });
            if (!string.IsNullOrEmpty(company.CompanyCode))
            {
                paramertList.Add(new object[] { "@company_code", company.CompanyCode.Trim() });
            }
            else
            {
                paramertList.Add(new object[] { "@company_code", company.CompanyCode});
            }
            paramertList.Add(new object[] { "@company_address_1", company.CompanyAddress1.Trim() });
            if (!string.IsNullOrEmpty(company.CompanyAddress2))
            {
                company.CompanyAddress2.Trim();
                paramertList.Add(new object[] { "@company_address_2", company.CompanyAddress2.Trim() });
            }

            paramertList.Add(new object[] { "@stateId", company.StateId });
            paramertList.Add(new object[] { "@city", company.City.Trim() });
            paramertList.Add(new object[] { "@zip", company.Zip.Trim() });
            if (!string.IsNullOrEmpty(company.Email))
            {
                company.Email.Trim();
            }
            if (!string.IsNullOrEmpty(company.PhoneNum2))
            {
                company.PhoneNum2.Trim();
            }
            if (!string.IsNullOrEmpty(company.PhoneNum3))
            {
                company.PhoneNum3.Trim();
            }
            paramertList.Add(new object[] { "@email", company.Email });
            paramertList.Add(new object[] { "@phone_num_1", company.PhoneNum1 });
            paramertList.Add(new object[] { "@phone_num_2", company.PhoneNum2 });
            paramertList.Add(new object[] { "@phone_num_3", company.PhoneNum3 });
            paramertList.Add(new object[] { "@fax", company.Fax });
            paramertList.Add(new object[] { "@website_url", company.WebsiteUrl });
            paramertList.Add(new object[] { "@created_by", company.CreatedBy });
            paramertList.Add(new object[] { "@created_date", DateTime.Now });
            paramertList.Add(new object[] { "@company_type", company.TypeId });
            paramertList.Add(new object[] { "@reg_company_id", company.RegCompanyId });


            try
            {
                return dataHandler.ExecuteSQLReturn("spInsertNonRegisteredCompanyAtDashboard", paramertList);
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        public ActionResult CreatePartnerCompanyAtDashboard(PartnerCompany  partnerCompany)
        {
            //check user is super admin or admin
            if ((userData.RoleId == 1) || (userData.RoleId == 2))
            {
                //check object is not null
                if (partnerCompany != null)
                {
                  //set company zip code
                    partnerCompany.Zip = partnerCompany.ZipPre;
                    if (partnerCompany.Extension != null)
                        partnerCompany.Zip += "-" + partnerCompany.Extension;
                    //assign created by property value as logged user id
                    partnerCompany.CreatedBy = userData.UserId;
                    //assign created company type - (1-Lender, 2-Dealer)
                    partnerCompany.TypeId = (userData.CompanyType == 1) ? 2 : 1; ;
                   
                    CompanyAccess ca = new CompanyAccess();
                 
                    partnerCompany.RegCompanyId = userData.Company_Id; //regCompany.CompanyId;  asanka
                    //check result of create partner company
                    if (ca.InsertNonRegisteredCompanyAtDashboard(partnerCompany) == 1)
                    {
                        //assign result to TempData object
                        TempData["partnerReslt"] = 1;
                    }
                    else
                    {
                        TempData["partnerReslt"] = 0;
                    }
                    //return to create partner company page
                        return RedirectToAction("CreatePartnerCompanyAtDashboard");
                }
                else
                {
                    //if partner company object is null return to login page
                    return new HttpStatusCodeResult(404);
                }
            }
            else
            {
                //if user is not a super admin or admin return to login page
                return new HttpStatusCodeResult(404);
            }

            
        }
        public List<PartnerCompany> GetNonRegCompanyDetailsByRegCompanyId2(int company_Id)
        {
            List<PartnerCompany> companyList = new List<PartnerCompany>();
            DataHandler dataHandler = new DataHandler();
            List<object[]> paramertList = new List<object[]>();
            paramertList.Add(new object[] { "@reg_company_id", company_Id });

            try
            {
                DataSet dsCompany = dataHandler.GetDataSet("spGetNonRegCompanyDetailsByRegCompanyId", paramertList);
                if (dsCompany != null && dsCompany.Tables.Count != 0)
                {
                    foreach (DataRow dataRow in dsCompany.Tables[0].Rows)
                    {
                        PartnerCompany company = new PartnerCompany();
                        company.CompanyId = int.Parse(dataRow["company_Id"].ToString());
                        company.CompanyName = dataRow["company_name"].ToString();
                        company.CompanyCode = dataRow["company_code"].ToString();
                        company.CompanyAddress1 = dataRow["company_address_1"].ToString();
                        company.CompanyAddress2 = dataRow["company_address_2"].ToString();
                        company.StateId = int.Parse(dataRow["stateId"].ToString());
                        company.City = dataRow["city"].ToString();
                        company.Zip = dataRow["zip"].ToString();
                        string[] zipWithExtention = company.Zip.Split('-');

                        if (zipWithExtention[0] != null) company.ZipPre = zipWithExtention[0];
                        if (zipWithExtention.Count() >= 2 && zipWithExtention[1] != null) company.Extension = zipWithExtention[1];

                        company.Email = dataRow["email"].ToString();
                        company.PhoneNum1 = dataRow["phone_num_1"].ToString();
                        if (!string.IsNullOrEmpty(dataRow["phone_num_2"].ToString()))
                        {
                            company.PhoneNum2 = dataRow["phone_num_2"].ToString().Trim();
                        }
                        if (!string.IsNullOrEmpty(dataRow["phone_num_3"].ToString()))
                        {
                            company.PhoneNum3 = dataRow["phone_num_3"].ToString().Trim();
                        }
                        if (!string.IsNullOrEmpty(dataRow["fax"].ToString()))
                        {
                            company.Fax = dataRow["fax"].ToString();
                        }
                        if (!string.IsNullOrEmpty(dsCompany.Tables[0].Rows[0]["website_url"].ToString()))
                        {
                            company.WebsiteUrl = dataRow["website_url"].ToString().Trim();
                        }
                        company.TypeId = int.Parse(dataRow["company_type"].ToString());
                        company.CompanyType = (company.TypeId == 1) ? "Lender" : "Dealer";
                        companyList.Add(company);
                    }
                    return companyList;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }