bool Validate(ref StoreManifest stm)
        {
            FormCollection collection = new FormCollection(ConvertRawUrlToQuerystring());

            stm.Store = collection[UIStore.txtStore.ToString()].ToString();
            stm.Address = collection[UIStore.txtAddress.ToString()].ToString();
            stm.FullAddress = collection[UIStore.txtFullAddress.ToString()].ToString();
            stm.City = collection[UIStore.txtCity.ToString()].ToString();
            stm.Country = collection[UIStore.txtCountry.ToString()].ToString();
            stm.Email1 = collection[UIStore.txtEmail.ToString()].ToString();
            stm.Email2 = collection[UIStore.txtEmail2.ToString()].ToString();
            stm.hidState = Convert.ToInt32(collection[UIStore.hidState.ToString()]);
            stm.ID = Convert.ToInt32(collection[UIStore.hidID.ToString()].ToString());
            stm.Latitude = collection[UIStore.hidLatitude.ToString()].ToString(); ;
            stm.Longitude = collection[UIStore.hidLongitude.ToString()].ToString(); ;

            stm.Phone1 = collection[UIStore.txtPhone1.ToString()].ToString(); ;
            stm.Phone2 = collection[UIStore.txtPhone2.ToString()].ToString(); ;
            stm.State = collection[UIStore.txtState.ToString()].ToString(); ;
            stm.Code = collection[UIStore.txtCode.ToString()].ToString(); ;
            //stm.Street_Name = collection[UIStore.txtStreetName.ToString()].ToString(); ;
            stm.Street_No = collection[UIStore.txtStreetNo.ToString()].ToString(); ;
            stm.Website = collection[UIStore.txtWebsite.ToString()].ToString(); ;
            stm.ZipCode = collection[UIStore.txtZipCode.ToString()].ToString(); ;

            stm.Is_Email1_Display = collection[UIStore.Is_Email1_Display.ToString()] == null ? false : true;
            stm.Is_Email2_Display = collection[UIStore.Is_Email2_Display.ToString()] == null ? false : true;
            stm.Is_Phone1_Display = collection[UIStore.Is_Phone1_Display.ToString()] == null ? false : true;
            stm.Is_Phone2_Display = collection[UIStore.Is_Phone2_Display.ToString()] == null ? false : true;
            stm.Is_Website_Display = collection[UIStore.Is_Website_Display.ToString()] == null ? false : true;


            if (collection[UIStore.Is_Active.ToString()] == null)
            {
                stm.Is_Active = false;
            }
            else
            {
                stm.Is_Active = true;
            }



            if (stm.Code.Length <= 2)
            {
                stm.CodeError = "Enter Valid account id";
                stm.Has_Error = true;
            }



            if (stm.Store.Length <= 2)
            {
                stm.StoreError = "Enter Valid store name";
                stm.Has_Error = true;
            }


            if (stm.Address.Length <= 3)
            {
                stm.AddressError = "Enter Valid Address";
                stm.Has_Error = true;
            }

            if (stm.FullAddress.Length <= 3)
            {
                stm.FullAddressError = "Enter Valid Address";
                stm.Has_Error = true;
            }


            if (stm.City.Length <= 2)
            {
                stm.CityError = "Enter valid city";
                stm.Has_Error = true;
            }

            if (stm.Country.Length <= 0)
            {
                stm.CountryError = "Enter sales country";
                stm.Has_Error = true;
            }

            if (!isEmail(stm.Email1.Trim()) && stm.Email1.Trim().Length != 0)
            {
                stm.Email1Error = "Enter valid Email";
                stm.Has_Error = true;
            }

            if (!isEmail(stm.Email2.Trim()) && stm.Email2.Trim().Length != 0)
            {
                stm.Email2Error = "Enter valid Email2";
                stm.Has_Error = true;
            }

            if (stm.Latitude.Length == 0 || stm.Longitude.Length == 0)
            {
                stm.AddressError = "Enter valid address";
                stm.Has_Error = true;
            }

            if (stm.Phone1.Length < 2 && stm.Phone1.Length != 0)
            {
                stm.Phone1Error = "Enter valid Phone";
                stm.Has_Error = true;
            }

            if (stm.Phone2.Length < 2 && stm.Phone2.Length != 0)
            {
                stm.Phone2Error = "Enter valid Phone";
                stm.Has_Error = true;
            }






            if (!IsUrlValid(stm.Website.Trim()) && stm.Website.Trim().Length != 0)
            {
                stm.WebsiteError = "Enter valid Website";
                stm.Has_Error = true;
            }

            if (!IsNumeric(stm.ZipCode))
            {
                stm.ZipCodeError = "Enter valid Zip Code";
                stm.Has_Error = true;
            }


            return stm.Has_Error;
        }
        public JsonResult Delete(string codeSLSP, string SalesRepCode, string Territory)
        {


            StoreManifest spm = new StoreManifest();



            //BusinessLogic.SalesPerson.SalesPerson sp = new BusinessLogic.SalesPerson.SalesPerson();
            //DataSet.DSParameter ds = new DataSet.DSParameter();
            //ds.ARSAP.AddARSAPRow(codeSLSP, "", SalesRepCode, Territory, "");
            //if (sp.Delete(ds))
            //{
            //    spm.Has_Error = false;
            //    MvcApplication.RefreshData("", null, System.Web.Caching.CacheItemRemovedReason.DependencyChanged);
            //}
            //else
            //{
            //    spm.Has_Error = true;

            //}

            return this.Json(spm, JsonRequestBehavior.AllowGet);
        }
        bool Validate(ref StoreManifest stm)
        {
            FormCollection collection = new FormCollection(ConvertRawUrlToQuerystring());

            stm.Marker = collection[UIMarker.txtMarker.ToString()].ToString();
            stm.Address = collection[UIMarker.txtAddress.ToString()].ToString();
            stm.City= collection[UIMarker.txtCity.ToString()].ToString();
            stm.City = collection[UIMarker.txtCity.ToString()].ToString();
            stm.State= collection[UIMarker.txtState.ToString()].ToString();
            stm.Country = collection[UIMarker.txtCountry.ToString()].ToString();
            stm.hidState = Convert.ToInt32(collection[UIMarker.hidState.ToString()]);
            stm.ID = Convert.ToInt32( collection[UIMarker.hidID.ToString()].ToString() ) ;
            stm.Latitude = collection[UIMarker.hidLatitude.ToString()].ToString(); ;
            stm.Longitude = collection[UIMarker.hidLongitude.ToString()].ToString(); ;



            if (collection[UIMarker.is_Recurring_Event.ToString()] == null)
            {
                stm.Is_Recurring_Event = false;
            }
            else
            {
                stm.Is_Recurring_Event = true;
            }



            if (stm.Marker.Length <= 2)
            {
                stm.MarkerError = "Enter Valid Marker name";
                stm.Has_Error = true;
            }



            if (stm.Address.Length <= 2)
            {
                stm.AddressError = "Enter Valid Address";
                stm.Has_Error = true;
            }


           

            if (stm.City.Length <= 3)
            {
                stm.CityError = "Enter City";
                stm.Has_Error = true;
            }


            if (stm.State.Length <= 2)
            {
                stm.StateError = "Enter state";
                stm.Has_Error = true;
            }

            if (stm.Country.Length <= 0)
            {
                stm.CountryError = "Enter sales country";
                stm.Has_Error = true;
            }

            

            if (stm.Latitude.Length == 0 || stm.Longitude.Length == 0)
            {
                stm.AddressError = "Enter valid address";
                stm.Has_Error = true;
            }


            return stm.Has_Error;
        }
        public JsonResult Save()
        {


            StoreManifest stm = new StoreManifest();


            if (!Validate(ref stm))
            {
                BusinessLogic.Distributor.Distributor sp = new BusinessLogic.Distributor.Distributor();
                DataSet.DSParameter ds = new DataSet.DSParameter();

                ds.Distributor.IDColumn.ReadOnly = false;


                ds.Distributor.AddDistributorRow(stm.Is_Active, Convert.ToInt32(stm.Code), stm.Store, stm.City, stm.State,
                    stm.FullAddress, Convert.ToDecimal(stm.Latitude), Convert.ToDecimal(stm.Longitude), stm.Email1, stm.ZipCode, stm.Address, stm.Street_No,
                    stm.Street_Name, stm.Country, stm.Phone1, stm.Phone2, stm.Email2, stm.Website, stm.Is_Email1_Display, stm.Is_Email2_Display,
                    stm.Is_Phone1_Display, stm.Is_Phone2_Display, stm.Is_Website_Display);
                ds.EnforceConstraints = false;
                ds.Distributor[0]["ID"] = Convert.ToInt32(stm.ID);

                if (stm.hidState == 3)
                {
                    sp.New(ds);
                }
                else
                {
                    sp.Update(ds);
                }
                UpdateCache();
            }


            return this.Json(stm, JsonRequestBehavior.AllowGet);
        }
        public JsonResult Save()
        {


            StoreManifest stm = new StoreManifest();

             
            if (!Validate(ref stm))
            {
                BusinessLogic.Marker.Marker sp = new BusinessLogic.Marker.Marker();
                DataSet.DSParameter ds = new DataSet.DSParameter();

                ds.Marker.Marker_IDColumn.ReadOnly = false;


                ds.Marker.AddMarkerRow(stm.Marker, stm.Address, stm.City, stm.State, stm.Country,Convert.ToDecimal( stm.Latitude ), Convert.ToDecimal(stm.Longitude), stm.Is_Recurring_Event, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                   
                ds.EnforceConstraints = false;
                ds.Marker[0]["Marker_ID"] = Convert.ToInt32(stm.ID);

                if (stm.hidState == 3)
                {
                    sp.New(ds);
                }
                else
                {
                    sp.Update(ds);
                }
                UpdateCache();
            }


            return this.Json(stm, JsonRequestBehavior.AllowGet);
        }