Пример #1
0
        public async Task <IActionResult> AddCity([FromBody] CityForCreationDto city, int id)
        {
            if (city == null)
            {
                return(BadRequest());
            }
            var cityToAdd = Mapper.Map <City>(city);
            var country   = await _repository.GetCountry(id);

            if (country == null)
            {
                return(NotFound());
            }
            cityToAdd.CountryId = country.Id;
            _repository.AddCityForCountry(cityToAdd);
            if (!await _repository.Save())
            {
                throw new Exception("Failed");
            }
            return(NoContent());
        }