public IActionResult AddCity([FromBody] AddCityModel addCityModel) { if (addCityModel == null) { return(BadRequest()); } if (_dataStore.Cities.FirstOrDefault(c => c.Name == addCityModel.Name) != null) { return(Conflict("The city with name specified already exists")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } int newId = _dataStore.GetNewId(); var city = new City(newId, addCityModel.Name, addCityModel.Description, addCityModel.NumberOfPoi); _dataStore.Cities.Add(city); var getCityModel = new GetCityModel(newId, addCityModel.Name, addCityModel.Description, addCityModel.NumberOfPoi); return(CreatedAtAction("GetCity", new { id = newId }, getCityModel)); } //добавить город
public IActionResult AddCity([FromBody] AddCityModel addCityModel) { _logger.LogInformation($"{nameof(AddCity)}, {nameof(addCityModel)} called"); if (addCityModel == null) { return(BadRequest()); } if (_dataStore.Cities.FirstOrDefault(c => c.Name == addCityModel.Name) != null) { return(Conflict("The city with name specified already exists")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); //передаем в badrequest ошибку } int newId = _dataStore.GetNewId(); var city = new City( newId, addCityModel.Name, addCityModel.Description, addCityModel.NumberOfPoi); _dataStore.Cities.Add(city); var getCityModel = new GetCityModel( newId, addCityModel.Name, addCityModel.Description, addCityModel.NumberOfPoi); return(CreatedAtAction( "GetCity", new { id = newId }, getCityModel)); }