/// <summary> /// Finds the city for the particular state and country /// </summary> /// <param name="cityName">The city name</param> /// <param name="stateName">the state name</param> /// <param name="countryName">the country name</param> /// <returns>the city or null if empty</returns> /// <exception cref="">AliKuli.Exceptions.MiscNS.NoDataException - if parameters are incomplete.</exception> /// <exception cref="">AliKuli.Exceptions.PlacesNS.StateNotFoundException - if state not in db.</exception> public City FindByName(string cityName, string stateName, string countryName) { if (cityName.IsNullOrEmpty()) { throw new ErrorHandlerLibrary.ExceptionsNS.NoDataException("No city name received. CityDAL.FindByName."); } if (countryName.IsNullOrEmpty()) { throw new ErrorHandlerLibrary.ExceptionsNS.NoDataException("No country name received. CityDAL.FindByName."); } if (stateName.IsNullOrEmpty()) { stateName = countryName; } State state = new StateDAL(_db, ErrorsGlobal).FindByName(stateName, countryName); if (state == null) { throw new ErrorHandlerLibrary.ExceptionsNS.StateNotFoundException("State Not found. CityDAL.FindByName."); } City city = this.SearchFor(x => x.Name.ToLower() == cityName.ToLower() && x.StateId == state.Id) .FirstOrDefault(); return(city); }
private void Create_BlankStateForCountry(Country entity) { State state = new StateDAL(_db, ErrorsGlobal).Factory(); state.Name = entity.Name; state.StateAbbreviation = entity.Abbreviation; state.MetaData.IsAutoCreated = true; state.MetaData.Comment = "Every country also has a default blank state."; entity.States.Add(state); }