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)); } }
public PointOfInterestViewModel Register(PointOfInterestDomainModel PointOfInterest) { var pointOfInterest = _Mapper.Map <PointOfInterestDomainModel, PointOfInterest>(PointOfInterest); var newPointOfInterest = _PointOfInterestService.Create(pointOfInterest); return(_Mapper.Map <PointOfInterest, PointOfInterestViewModel>(newPointOfInterest)); }
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)); }