Пример #1
0
    public int SaveAddress(int?AddressId)
    {
        bool LoadMap = IsLoadMap();

        var objAddress = new Address()
        {
            Address1 = RemoveLastComma(txtAddress1.Text).zFirstCharToUpper(),
            Address2 = RemoveLastComma(txtAddress2.Text).zFirstCharToUpper(),
            Pincode  = LoadMap ? txtPincodeMap.Text : txtPincode.Text,

            Latitude  = txtLatitude.Text,
            Longitude = txtLongitude.Text,
        };

        if (LoadMap)
        {
            objAddress.CountryId = CU.GetCountryId(txtCountryMap.Text);
            objAddress.StateId   = CU.GetStateId(objAddress.CountryId, txtStateMap.Text);
            objAddress.CityId    = CU.GetCityId(objAddress.StateId, txtCityMap.Text);
            objAddress.AreaId    = CU.GetAreaId(objAddress.CityId, txtAreaMap.Text, objAddress.Pincode);
        }
        else
        {
            #region Set Country Value

            if (chkCountry.Checked)
            {
                objAddress.CountryId = CU.GetCountryId(txtOtherCountry.Text);
            }
            else
            {
                objAddress.CountryId = ddlCountry.zToInt();
            }

            #endregion Set Country Value

            #region Set State Value

            if (chkState.Checked)
            {
                objAddress.StateId = CU.GetStateId(objAddress.CountryId, txtOtherState.Text);
            }
            else
            {
                objAddress.StateId = ddlState.zToInt();
            }

            #endregion Set State Value

            #region Set City Value

            if (chkCity.Checked)
            {
                objAddress.CityId = CU.GetCityId(objAddress.StateId, txtOtherCity.Text);
            }
            else
            {
                objAddress.CityId = ddlCity.zToInt();
            }

            #endregion Set City Value

            #region Set Area Value

            if (chkArea.Checked)
            {
                objAddress.AreaId = CU.GetAreaId(objAddress.CityId, txtOtherArea.Text, txtPincode.Text);
            }
            else
            {
                objAddress.AreaId = ddlArea.zToInt();
            }

            #endregion Set Area Value
        }

        if (AddressId.HasValue && AddressId != 0)
        {
            objAddress.AddressId = AddressId;
            objAddress.UpdateAsync();
        }
        else
        {
            AddressId = objAddress.Insert();
        }

        return(AddressId.Value);
    }