public JsonResult GetCountryStates(int?countryId) { var states = new List <StateDTO>(); if (countryId != null) { states = _geoServices.GetStates((short)countryId).ToList(); } return(Json(states, JsonRequestBehavior.AllowGet)); }
private bool IsAddressValid(ref BillingAddressDTO address, out string error) { error = string.Empty; if (address == null) { error = "address required"; return(false); } if (address.CountryId == null) { error = "Country required"; return(false); } if (address.CountryId != null && Constants.COUNTRIES_WITH_STATES.Contains((int)address.CountryId) && address.StateId == null) { error = "State required"; return(false); } if (String.IsNullOrEmpty(address.PostalCode)) { error = "Postal code required"; return(false); } if (String.IsNullOrEmpty(address.City)) { error = "City required"; return(false); } if (String.IsNullOrEmpty(address.Street1)) { error = "Street required"; return(false); } if (String.IsNullOrEmpty(address.BillingFirstName)) { error = "Billing FirstName required"; return(false); } if (String.IsNullOrEmpty(address.BillingLastName)) { error = "Billing LastName required"; return(false); } var cid = address.CountryId; var country = _geoServices.ActiveCountries().FirstOrDefault(x => x.CountryId == cid); if (country != null) { address.CountryCode = country.A2; } else { error = "country not found"; return(false); } if (address.StateId != null) { var sid = address.StateId; var state = _geoServices.GetStates((short)cid).FirstOrDefault(x => x.StateId == sid); if (state != null) { address.StateCode = state.StateCode; } } address.UserId = CurrentUserId; return(true); }