public IActionResult Post([FromBody] ReviewViewModel reviewViewModel) { if (reviewViewModel == null) { return(BadRequest()); } if (this.ReviewExists(reviewViewModel.Name, reviewViewModel.Author)) { return(ValidationProblem($"Review of {reviewViewModel.TargetBeer} from {reviewViewModel.Author} already exists.")); } //TODO Need check if exist if (reviewViewModel.TargetBeer == null) { return(BadRequest("Target beer not found.")); } var reviewDTO = new ReviewDTO { Name = reviewViewModel.Name, Text = reviewViewModel.Text, Rating = reviewViewModel.Rating, TargetBeer = reviewViewModel.TargetBeer, Author = reviewViewModel.Author, }; var review = _reviewServices.CreateReview(reviewDTO); return(Created("Post", review)); }
public int CreateReview(ReviewModel review) { Mapper.Initialize(cfg => { cfg.CreateMap <ReviewModel, ReviewEntity>() .ForMember(dest => dest.Restaurant, opt => opt.Ignore()) .ForMember(dest => dest.User, opt => opt.Ignore()); }); var reviewEntity = Mapper.Map <ReviewModel, ReviewEntity>(review); return(_reviewServices.CreateReview(reviewEntity)); }