public IActionResult CreatePointOfInterest(int cityId,
                                                   [FromBody] PointsOfInterestsForCreationDto pointOfInterest)
        {
            if (pointOfInterest.Description == pointOfInterest.Name)
            {
                ModelState.AddModelError(
                    "Description",
                    "Name and description should be different."
                    );
            }

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

            if (!_cityInfoRepository.CityExists(cityId))
            {
                return(NotFound());
            }

            var finalPointOfInterest = _mapper.Map <Entities.PointOfInterest>(pointOfInterest);

            _cityInfoRepository.AddPointOfInterestsForCity(cityId, finalPointOfInterest);
            _cityInfoRepository.Save();

            var createdPointOfInterest = _mapper.Map <PointsOfInterestDto>(finalPointOfInterest);

            return(CreatedAtRoute(
                       "GetPointOfInterest",
                       new { cityId, id = createdPointOfInterest.Id },
                       createdPointOfInterest));
        }
        public IActionResult CreatePointOfInterest(int cityId,
                                                   [FromBody] PointsOfInterestsForCreationDto pointOfInterest)
        {
            //a problem that might occur is that the post request might not be deserialized into the point of interests for creation dto
            // if it cant be deserialized then the point of interests parameter will be null
            // for that we return a bad request because it's the consumer's error
            if (pointOfInterest == null)
            {
                return(BadRequest());
            }
            // adding a custom error when adding the same text in both name and descr property
            if (pointOfInterest.Description == pointOfInterest.Name)
            {
                ModelState.AddModelError("Description", "The provided Description should differ from the Name");
            }

            // if one of the properties does not adhere to our PointsofInterestsCreation model we send a bad request
            if (!ModelState.IsValid)
            {
                //returning the ModelState to inform the client what went wrong
                return(BadRequest(ModelState));
            }

            //the consumer might send a request to a resource URI that does not exists
            //e.g. adding a point of interests to a non-existing city so we check for that
            //and return not found if the city does not exists
            var city = CitiesDataStore.Current.Cities.FirstOrDefault(c => c.Id == cityId);

            if (city == null)
            {
                return(NotFound());
            }
            //new we can create the new point of interest
            // *for now* we need to calculate the id for the new-to-be-created point of interest
            // calculate the id by running through all the current point
            //of interests accross cities and getting the heighest value
            var maxPointOfInterest = CitiesDataStore.Current.Cities.SelectMany(p => p.PointOfInterests).Max(i => i.Id);

            var newPointOfIntersst = new PointOfInterestsDto()
            {
                //we add one (1) and we use it when creating a new point of interest
                Id          = ++maxPointOfInterest,
                Name        = pointOfInterest.Name,
                Description = pointOfInterest.Description
            };

            city.PointOfInterests.Add(newPointOfIntersst);

            return(CreatedAtRoute("GetPointOfInterest", new
            {
                cityId = cityId,
                pointId = newPointOfIntersst.Id
            }, newPointOfIntersst));
        }