//Get
        public ActionResult Client(int? clientID)
        {
            BindLookups();

            BLClientSite clientBL = new BLClientSite();
            tblClientSite editclient = new tblClientSite();
            editclient = clientBL.GetClientSite(clientID.Value);

            if (Request.IsAjaxRequest())
                return PartialView(editclient);
            else
                return View(editclient);
        }
        public ActionResult Client(tblClientSite clientSite)
        {
            try
            {
                BLClientSite clientBL = new BLClientSite();
                clientSite.CustomerID = SessionHelper.UserSession.CustomerID;
                clientBL.SaveClientSite(clientSite);
            }
            catch
            {
                ModelState.AddModelError("", "Please provide valid User Name/Password.");
                return Json(new { errors = KeyValue.GetErrorsFromModelState(ViewData) });
            }

            return Json(new { success = true });
        }
        /// Get All Client Site - CustomerID
        /// 
        public List<tblClientSite> GetAllClientSite(int CustomerID, int pageNumber, int pageSize, int sortColumnIndex, string sortOrder, string searchText, ref int totalRecords)
        {
            List<tblClientSite> lstClientSite = new List<tblClientSite>();

            int errorNum = 0;
            string errorDesc = "";
            DataAccess.resetParams();
            DataAccess.addSqlParam("@CustomerID", ParameterDirection.Input, 16, MySqlDbType.Int32, CustomerID);
            DataAccess.addSqlParam("@pageNumber", ParameterDirection.Input, 16, MySqlDbType.Int32, pageNumber);
            DataAccess.addSqlParam("@pageRecord", ParameterDirection.Input, 16, MySqlDbType.Int32, pageSize);
            DataAccess.addSqlParam("@sortColumnIndex", ParameterDirection.Input, 16, MySqlDbType.Int32, sortColumnIndex);
            DataAccess.addSqlParam("@searchOrder", ParameterDirection.Input, 4, MySqlDbType.VarChar, sortOrder);
            DataAccess.addSqlParam("@searchText", ParameterDirection.Input, 100, MySqlDbType.VarChar, searchText);

            DataSet ds = DataAccess.ExecuteDataSet(GET_ALL_CLIENT_SITE, ref errorNum, ref errorDesc);
            tblClientSite Clientsite = new tblClientSite();
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                DataTable dtClientsite = ds.Tables[0];
                DataTable dtTotalRecords = ds.Tables[1];
                totalRecords = Common.ConvertToInt(dtTotalRecords.Rows[0], "TotalRecords");
                if (dtClientsite != null && dtClientsite.Rows.Count > 0)
                {
                    foreach (DataRow dr in dtClientsite.Rows)
                    {
                        Clientsite = new tblClientSite();
                        Clientsite.ClientID = Common.ConvertToInt(dr, "ClientID");
                        Clientsite.CustomerID = Common.ConvertToInt(dr, "CustomerID");
                        Clientsite.IsActive = Common.ConvertToInt(dr, "Isactive");
                        Clientsite.BusinessName = Common.ConvertToString(dr, "BusinessName");
                        Clientsite.ServiceType = new ServiceType();
                        Clientsite.ServiceType.ID = Common.ConvertToInt(dr, "ServiceType");
                        Clientsite.ServiceType.Name = LookUpValue.GetServiceType(Clientsite.ServiceType.ID.Value);
                        Clientsite.Status = new SetUpStaus();
                        Clientsite.Status.ID = Common.ConvertToInt(dr, "Status");
                        Clientsite.Status.Name = LookUpValue.GetSetUpStaus(Clientsite.Status.ID.Value);
                        Clientsite.TimeZone = new TimeZoneFX();
                        Clientsite.TimeZone.ID = Common.ConvertToInt(dr, "TimeZone");
                        Clientsite.TimeZone.Name = LookUpValue.GetTimeZone(Clientsite.TimeZone.ID.Value);
                        lstClientSite.Add(Clientsite);
                    }
                }
            }
            return lstClientSite;
        }
        public int SaveClientSite(tblClientSite clientSite)
        {
            int errorNum = 0;
            string errorDesc = "";

            DataAccess.resetParams();
            DataAccess.addSqlParam("@oClientID", ParameterDirection.Input, 16, MySqlDbType.Int32, clientSite.ClientID);
            DataAccess.addSqlParam("@CustomerID", ParameterDirection.Input, 16, MySqlDbType.Int32, clientSite.CustomerID);
            DataAccess.addSqlParam("@BusinessName", ParameterDirection.Input, 100, MySqlDbType.VarChar, clientSite.BusinessName);
            DataAccess.addSqlParam("@ServiceType", ParameterDirection.Input, 16, MySqlDbType.Int32, clientSite.ServiceType.ID);
            DataAccess.addSqlParam("@ClientStatus", ParameterDirection.Input, 16, MySqlDbType.Int32, clientSite.Status.ID);
            DataAccess.addSqlParam("@TimeZone", ParameterDirection.Input, 16, MySqlDbType.Int32, clientSite.TimeZone.ID);
            DataAccess.addSqlParam("@Isactive", ParameterDirection.Input, 16, MySqlDbType.Int16,1);
            DataAccess.addSqlParam("@Identity", ParameterDirection.InputOutput, 16, MySqlDbType.Int32);
            DataAccess.ExecuteNonQuery(SET_CLIENT_SITE, ref errorNum, ref errorDesc);

            return Common.ConvertToInt(DataAccess.getSQLParam("@Identity").ToString());
        }
        public List<tblClientSite> GetCustomerClient(int CustomerID)
        {
            List<tblClientSite> lstClientSite = new List<tblClientSite>();

            int errorNum = 0;
            string errorDesc = "";
            DataAccess.resetParams();
            DataAccess.addSqlParam("@CustomerID", ParameterDirection.Input, 16, MySqlDbType.Int32, CustomerID);

            DataSet ds = DataAccess.ExecuteDataSet(Get_CustomerClient, ref errorNum, ref errorDesc);
            tblClientSite Clientsite = new tblClientSite();
            if (ds != null && ds.Tables.Count > 0)
            {
                DataTable dtClientsite = ds.Tables[0];

                if (dtClientsite != null && dtClientsite.Rows.Count > 0)
                {
                    foreach (DataRow dr in dtClientsite.Rows)
                    {
                        Clientsite = new tblClientSite();
                        Clientsite.ClientID = Common.ConvertToInt(dr, "ClientID");
                        Clientsite.CustomerID = Common.ConvertToInt(dr, "CustomerID");
                        Clientsite.BusinessName = Common.ConvertToString(dr, "BusinessName");
                        Clientsite.ServiceType = new ServiceType();
                        Clientsite.ServiceType.ID = Common.ConvertToInt(dr, "ServiceType");
                        Clientsite.ServiceType.Name = LookUpValue.GetServiceType(Clientsite.ServiceType.ID.Value);
                        Clientsite.Status = new SetUpStaus();
                        Clientsite.Status.ID = Common.ConvertToInt(dr, "Status");
                        Clientsite.Status.Name = LookUpValue.GetSetUpStaus(Clientsite.Status.ID.Value);
                        Clientsite.TimeZone = new TimeZoneFX();
                        Clientsite.TimeZone.ID = Common.ConvertToInt(dr, "TimeZone");
                        Clientsite.TimeZone.Name = LookUpValue.GetTimeZone(Clientsite.TimeZone.ID.Value);
                        lstClientSite.Add(Clientsite);
                    }
                }
            }
            return lstClientSite;
        }
        /// <summary>
        /// Use Ciient ID in this function
        /// </summary>
        /// <param name="CustomerID"></param>
        /// <returns></returns>
        public tblClientSite GetClientSite(int ClientID)
        {
            int errorNum = 0;
            string errorDesc = "";

            DataAccess.resetParams();
            DataAccess.addSqlParam("@ClientID", ParameterDirection.Input, 16, MySqlDbType.Int32, ClientID);
            DataSet ds = DataAccess.ExecuteDataSet(GET_CLIENT_SITE, ref errorNum, ref errorDesc);
            tblClientSite Clientsite = new tblClientSite();
            if (ds != null && ds.Tables.Count > 0)
            {
                DataTable dtClientsite = ds.Tables[0];
                if (dtClientsite != null && dtClientsite.Rows.Count > 0)
                {
                    DataRow dr = dtClientsite.Rows[0];
                    Clientsite.ClientID = Common.ConvertToInt(dr, "ClientID");
                    Clientsite.CustomerID = Common.ConvertToInt(dr, "CustomerID");
                    Clientsite.IsActive = Common.ConvertToInt(dr, "Isactive");
                    Clientsite.BusinessName = Common.ConvertToString(dr, "BusinessName");
                    Clientsite.ServiceType = new ServiceType();
                    Clientsite.ServiceType.ID = Common.ConvertToInt(dr, "ServiceType");
                    Clientsite.ServiceType.Name = LookUpValue.GetServiceType(Clientsite.ServiceType.ID.Value);
                    Clientsite.Status = new SetUpStaus();
                    Clientsite.Status.ID = Common.ConvertToInt(dr, "Status");
                    Clientsite.Status.Name = LookUpValue.GetSetUpStaus(Clientsite.Status.ID.Value);
                    Clientsite.TimeZone = new TimeZoneFX();
                    Clientsite.TimeZone.ID = Common.ConvertToInt(dr, "TimeZone");
                    Clientsite.TimeZone.Name = LookUpValue.GetTimeZone(Clientsite.TimeZone.ID.Value);
                }
            }
            return Clientsite;
        }
        //Get
        public JsonResult JsonClient(int? ClientID)
        {
            BLClientSite clientBL = new BLClientSite();
            tblClientSite editclient = new tblClientSite();
            editclient = clientBL.GetClientSite(ClientID.Value);

            return Json(new { success = true, ClientTimeZone = editclient.TimeZone == null ? "" : editclient.TimeZone.Name, ClientStatus = editclient.Status == null ? "" : editclient.Status.Name }, JsonRequestBehavior.AllowGet);
        }
        //Get
        public ActionResult Index()
        {
            BLClientSite clientSiteBL = new BLClientSite();
            List<tblClientSite> lstClientSite = new List<tblClientSite>();
            lstClientSite.Add(new tblClientSite() { ClientID = 0, BusinessName = " -- Select -- " });
            lstClientSite.AddRange(clientSiteBL.GetCustomerClient(SessionHelper.UserSession.CustomerID));

            ViewBag.CustomerClientSites = lstClientSite;

            tblClientSite clientSite = new tblClientSite();
            clientSite.TimeZone = new TimeZoneFX();
            clientSite.Status = new SetUpStaus();

            if (Request.IsAjaxRequest())
                return PartialView(clientSite);
            else
                return View(clientSite);
        }