public IActionResult CreatePointsOfInterestDto(int cityid, [FromBody] PointsOfInterestCreationDto pointofinterest) { if (pointofinterest == null) { return(BadRequest()); // 400 } if (!ModelState.IsValid) { return(BadRequest()); } var city = CitiesDataStore.current.Cities.FirstOrDefault(c => c.Id == cityid); if (city == null) { return(NotFound()); } var maxPointofInterest = CitiesDataStore.current.Cities.SelectMany(c => c.Pointsofinterest).Max(p => p.Id); var finalpointsofinterest = new PointsOfInterestDto() { Id = ++maxPointofInterest, Name = pointofinterest.Name, Description = pointofinterest.Description }; city.Pointsofinterest.Add(finalpointsofinterest); return(CreatedAtRoute("GetPointsOfInterest", new { cityId = cityid, id = finalpointsofinterest.Id }, finalpointsofinterest)); }
public IActionResult CreatePointOfInterest(int cityId, [FromBody] PointsOfInterestCreationDto pointOfInterest) { if (pointOfInterest == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var city = CitiesDataStore.Current.Cities.FirstOrDefault(c => c.Id == cityId); if (city == null) { return(NotFound()); } var maxPointOfInterestID = CitiesDataStore.Current.Cities .SelectMany(c => c.PointsOfInterest).Max(p => p.Id); var newPointOfInterest = new PointsOfInterestDTO() { Id = ++maxPointOfInterestID, Name = pointOfInterest.Name, Description = pointOfInterest.Description }; city.PointsOfInterest.Add(newPointOfInterest); return(CreatedAtRoute("GetPointOfInterestById", new { cityId, newPointOfInterest.Id }, newPointOfInterest)); }