public async Task <IActionResult> PostAsync(int cityId, [FromBody] PointOfInterestDto pointOfInterest)
        {
            if (!_cityService.CityExists(cityId).Result)
            {
                return(NotFound());
            }

            if (pointOfInterest == null)
            {
                return(BadRequest());
            }

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

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                pointOfInterest.CityId = cityId;
                await _pointOfInterestService.Create(pointOfInterest);

                return(CreatedAtRoute("Get", new { id = pointOfInterest.Id }, pointOfInterest));
            }
            catch (Exception exception)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, exception.Message));
            }
        }
Esempio n. 2
0
        public PointOfInterestViewModel Register(PointOfInterestDomainModel PointOfInterest)
        {
            var pointOfInterest    = _Mapper.Map <PointOfInterestDomainModel, PointOfInterest>(PointOfInterest);
            var newPointOfInterest = _PointOfInterestService.Create(pointOfInterest);

            return(_Mapper.Map <PointOfInterest, PointOfInterestViewModel>(newPointOfInterest));
        }
Esempio n. 3
0
        public IActionResult setPointOfInterest(int cityId, [FromBody] PointOfInterestOfCreationDto pointOfInterest)
        {
            if (pointOfInterest == null)
            {
                return(BadRequest());
            }
            if (pointOfInterest.Name.Equals(pointOfInterest.Description))
            {
                ModelState.AddModelError("NameDesctiption", "the name and description can't be equal");
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var existCity = _cityService.GetById(cityId);

            if (existCity == null)
            {
                return(NotFound());
            }

            int createdId = _pointOfInterestservice.Create(new PointOfInterestDto()
            {
                Name        = pointOfInterest.Name,
                Description = pointOfInterest.Description,
                CityId      = cityId
            });

            return(CreatedAtRoute("getPointOfInterestById", new { cityId = cityId, id = createdId }, pointOfInterest));
        }