public IActionResult PartiallyUpdateCity(int cityId, [FromBody] JsonPatchDocument <CityForCreation> patchdoc) { var city = CitiesDataStore.Current.Cities.FirstOrDefault(c => c.Id == cityId); if (patchdoc == null || city == null) { return(BadRequest()); } var cityToPatch = new CityForCreation() { Name = city.Name, Description = city.Description }; patchdoc.ApplyTo(cityToPatch, ModelState); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } city.Name = cityToPatch.Name; city.Description = cityToPatch.Description; return(NoContent()); }
public IActionResult UpdateCity(int cityid, [FromBody] CityForCreation city) { var result = CitiesDataStore.Current.Cities.FirstOrDefault(c => c.Id == cityid); if (city == null || !ModelState.IsValid || result == null) { return(BadRequest(ModelState)); } result.Name = city.Name; result.Description = city.Description; return(NoContent()); }
public IActionResult CreateCity([FromBody] CityForCreation city) { if (city == null || !ModelState.IsValid) { return(BadRequest(ModelState)); } var MaxCityId = CitiesDataStore.Current.Cities.Select(c => c.Id).Max(); var FinalCity = new CityDto { Id = ++MaxCityId, Name = city.Name, Description = city.Description }; CitiesDataStore.Current.Cities.Add(FinalCity); return(CreatedAtRoute("GetCity", new { id = FinalCity.Id }, FinalCity)); }