public async Task <int> AddCityAsync(City city) { var cityEntity = _mapper.Map <City, CityEntity>(city); await _cityContext.Cities.AddAsync(cityEntity); await _cityContext.SaveChangesAsync(); return(cityEntity.Id); }
public async Task <City> CreateCityAsync(UpdateCityRequest city) { var duplicateCityDb = await _cityCntx.Cities.Where(c => c.CountryId == city.CountryId && String.CompareOrdinal(c.CityName, city.CityName) == 0).ToArrayAsync(); if (duplicateCityDb.Length > 0) { throw new DuplicateFoundException("Current city already exists"); } var added = _cityCntx.Cities.Add(_mapper.Map <CityDTO>(city)); var result = await _cityCntx.SaveChangesAsync(); if (result == 0) { throw new DuplicateFoundException("Can not add city with requested parameters"); } return(_mapper.Map <City>(added)); }