public IActionResult PartiallyUpdate(int cityid, int id, [FromBody] JsonPatchDocument <PointofIntrestforCreationDto> jsonPatchDocument) { if (jsonPatchDocument == null) { return(BadRequest()); } var city = CitiesDataStore.Current.Cities.FirstOrDefault(c => c.Id == cityid); if (city == null) { return(NotFound()); } var pointofintrest = city.PointofIntest.FirstOrDefault(c => c.Id == id); if (pointofintrest == null) { return(NotFound()); } var pointOfIntrestPatch = new PointofIntrestforCreationDto() { Name = pointofintrest.Name, Description = pointofintrest.Description }; jsonPatchDocument.ApplyTo(pointOfIntrestPatch, ModelState); pointofintrest.Name = pointOfIntrestPatch.Name; pointofintrest.Description = pointOfIntrestPatch.Description; return(NoContent()); }
public IActionResult CreatePointofIntrest(int CityId, [FromBody] PointofIntrestforCreationDto pointofIntrestforCreation) { if (pointofIntrestforCreation == null) { return(BadRequest()); } var city = CitiesDataStore.Current.Cities.FirstOrDefault(c => c.Id == CityId); if (city == null) { return(NotFound()); } var maxpointofIntrestId = CitiesDataStore.Current.Cities.SelectMany(c => c.PointofIntest).Max(p => p.Id); PointOfIntrestDto pointOfIntrestDto = new PointOfIntrestDto() { Id = maxpointofIntrestId++, Name = pointofIntrestforCreation.Name, Description = pointofIntrestforCreation.Description }; city.PointofIntest.Add(pointOfIntrestDto); return(CreatedAtRoute("GetPointOfIntrest", new { CityId = CityId, id = pointOfIntrestDto.Id }, pointOfIntrestDto)); }