Example #1
0
        public IActionResult CreatePointOfInterest(int cityId, [FromBody] PointsOfInterestForCreation poi)
        {
            if (poi.Name == poi.Description)
            {
                ModelState.AddModelError("Description", "Name and Description cannot be the same");
            }

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

            if (infoRepository.CityExists(cityId))
            {
                var finalPoi = mapper.Map <Entities.PointOfInterest>(poi);
                infoRepository.AddPoiForSingleCity(cityId, finalPoi);
                var response = mapper.Map <PointsOfInterestsDto>(finalPoi);
                return(CreatedAtRoute("CreatedPointOfInterest",
                                      new { cityId, response.Id }, response));
            }
            else
            {
                return(NotFound());
            }
        }
Example #2
0
        public IActionResult CreatePointOfInterest(int cityId, [FromBody] PointsOfInterestForCreation pointOfInterest)
        {
            if (pointOfInterest == null)
            {
                return(BadRequest());
            }

            if (pointOfInterest.Name == pointOfInterest.Description)
            {
                ModelState.AddModelError("Description", "The provided description should be different from the name.");
            }

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


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

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

            _cityInfoRepository.AddPointOfInterestForCity(cityId, finalPointOfInterest);

            if (!_cityInfoRepository.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            var createdPointOfInterestToReturn = Mapper.Map <PointsOfInterestDto>(finalPointOfInterest);

            return(CreatedAtRoute("GetPointOfInterest", new { cityId, id = finalPointOfInterest.Id }, createdPointOfInterestToReturn));
        }