public Country AddCountry(Country country) { try { CountryDB countryDB = CountryMapper.CountryToDBModel(country); context.Countries.Add(countryDB); context.SaveChanges(); Country newCountry = CountryMapper.CountryDBToBusinessModel(countryDB, country.Continent); return(newCountry); } catch (Exception ex) { throw ex; } }
public Country Find(string countryName) { try { CountryDB countryDB = context.Countries.Where(x => x.Name == countryName).FirstOrDefault(); if (countryDB != null) { return(CountryMapper.CountryDBToBusinessModel(countryDB)); } return(null); } catch (Exception ex) { throw ex; } }
public Country Find(int continentId, int countryId) { try { CountryDB countryDB = context.Countries.Find(countryId); ContinentDB continentDB = context.Continents.Find(continentId); if (continentDB != null && countryDB != null) { countryDB.ContinentId = continentId; countryDB.Continent = continentDB; Country country = CountryMapper.CountryDBToBusinessModel(countryDB); return(country); } return(null); } catch (Exception ex) { throw ex; } }