public IActionResult UpdateCity(int id, [FromBody] CityReplaceModel city) { if (city == null) { BadRequest(); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var updatedCity = _citiesDataStore.Cities .Where(x => x.Id == id) .FirstOrDefault(); if (updatedCity == null) { NotFound(); } updatedCity.Name = updatedCity.Name; updatedCity.Description = updatedCity.Description; updatedCity.NumberOfPointsOfInterest = updatedCity.NumberOfPointsOfInterest; return(NoContent()); }
public IActionResult ReplaceCity(int id, [FromBody] CityReplaceModel cityModel) { if (cityModel == null) { BadRequest(); } var city = _citiesDataStore.Cities .Where(x => x.Id == id) .FirstOrDefault(); if (city == null) { NotFound(); } city.Name = cityModel.Name; city.Description = cityModel.Description; city.NumberOfPointsOfInterest = cityModel.NumberOfPointsOfInterest; return(NoContent()); }
public IActionResult ReplaceCity(int id, [FromBody] CityReplaceModel cityReplaceModel) { if (cityReplaceModel == null) { return(BadRequest()); } var cityDto = _store.Cities.FirstOrDefault(x => x.Id == id); if (cityDto == null) { // 404 Not Found return(NotFound("404 Not Found")); } cityDto.Name = cityReplaceModel.Name; cityDto.Description = cityReplaceModel.Description; // it will be valid but but also we can return 200 OK // return NoContent(); // 200 OK return(Ok(new CityGetModel(cityDto))); }