Пример #1
0
        public IActionResult CreateCity([FromBody] CityCreateModel city)
        {
            if (city == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var newCityId = _citiesDataStore.Cities
                            .Max(x => x.Id) + 1;

            var newCity = new CityDataStoreModel()
            {
                Id          = newCityId,
                Name        = city.Name,
                Description = city.Description,
                NumberOfPointsOfInterest = city.NumberOfPointsOfInterest
            };

            _citiesDataStore.Cities.Add(newCity);

            return(CreatedAtRoute(
                       "GetCity",
                       new { id = newCityId },
                       newCity));
        }
Пример #2
0
 public CityPatchModel(CityDataStoreModel storeModel)
 {
     Name        = storeModel.Name;
     Description = storeModel.Description;
     NumberOfPointsOfInterest = storeModel.NumberOfPointsOfInterest;
 }