public IActionResult CreateReview(int resturantId, [FromBody] ReviewDTO review) { if (review == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest()); } var reviewEntity = Mapper.Map <Review>(review); _resturantRepository.AddReviewForResturant(resturantId, reviewEntity); if (!_resturantRepository.Save()) { return(StatusCode(500, "A problem happened when trying to save the entity.")); } var createdReview = Mapper.Map <ReviewDTO>(reviewEntity); return(CreatedAtRoute("GetReview", new { resturantId, reviewId = createdReview.Id }, createdReview)); }
public IActionResult CreateResturant([FromBody] ResturantDTO resturant) { if (resturant == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest()); } var resturantEntity = Mapper.Map <Resturant>(resturant); _resturantRepository.AddResturant(resturantEntity); if (!_resturantRepository.Save()) { return(StatusCode(500, "A problem happened when trying to save the entity.")); } var createdResturant = Mapper.Map <ResturantDTO>(resturantEntity); return(CreatedAtRoute("GetResturant", new { createdResturant.Id, includeReviews = true }, createdResturant)); }