protected void LogIn_ServerClick(object sender, EventArgs e) { try { int type = rbtHome.Checked ? 1 : rbtOffice.Checked ? 2 : 3; EnumAddressType addressType = (EnumAddressType)type; int userId = UserRepository.GetUserId(); bool isDefault = rbtYes.Checked ? true : false; using (AddressRepository addressRepository = new AddressRepository()) { if (_AddressId > 0) // Edit mode { AddressDetails address = addressRepository.Get(_AddressId); if (address != null) { address.UserId = userId; address.Address = txtAddress.Value.Trim(); address.Landmark = txtLandmark.Value.Trim(); address.Direction = txtDirection.Value.Trim(); address.CityId = Convert.ToInt32(ddlCity.SelectedValue.Trim()); address.AreaId = Convert.ToInt32(ddlArea.SelectedValue.Trim()); address.CountryId = Convert.ToInt32(ddlCountry.SelectedValue.Trim()); address.Pincode = txtPincode.Value.Trim(); address.AddressTypeId = (int)addressType; if (rbtOffice.Checked || rbtOther.Checked) { address.OtherAddress = txtOther.Value.Trim(); } else { address.OtherAddress = "NA"; } // if IsDefault is true then make other false. if (isDefault) { addressRepository.MakeOtherfalse(userId); } address.IsDefault = isDefault; addressRepository.Update(); Response.Redirect("~/Apps/User/AddressBookList.aspx?fg=2"); //SuccessMessage.Visible = true; //SuccessMessage.Text = "Address has been updated successfully."; } } else // Add mode { if (!addressRepository.GetAddressAlreadyExistsOrNot(userId, type)) { AddressDetails newAddress = new AddressDetails(); newAddress.UserId = userId; newAddress.Address = txtAddress.Value.Trim(); newAddress.Landmark = txtLandmark.Value.Trim(); newAddress.Direction = txtDirection.Value.Trim(); newAddress.CityId = Convert.ToInt32(ddlCity.SelectedValue.Trim()); newAddress.AreaId = Convert.ToInt32(ddlArea.SelectedValue.Trim()); newAddress.CountryId = Convert.ToInt32(ddlCountry.SelectedValue.Trim()); newAddress.Pincode = txtPincode.Value.Trim(); newAddress.AddressTypeId = (int)addressType; if (rbtOffice.Checked || rbtOther.Checked) { newAddress.OtherAddress = txtOther.Value.Trim(); } else { newAddress.OtherAddress = "NA"; } // if IsDefault is true then make other false. if (isDefault) { addressRepository.MakeOtherfalse(userId); } newAddress.IsDefault = isDefault; addressRepository.Add(newAddress); Response.Redirect("~/Apps/User/AddressBookList.aspx?fg=1"); //SuccessMessage.Visible = true; //SuccessMessage.Text = "New address has been added successfully."; } else { ErrorMessage.Visible = true; ErrorMessage.Text = "Address is already exists !!"; } } } } catch (Exception ex) { ErrorMessage.Visible = true; ErrorMessage.Text = ex.Message.ToString(); } }