private ProductReview CreateReviewFromRequest(ReviewRequest reviewRequest) { return new ProductReview { Title = reviewRequest.Title, Comment = reviewRequest.Comment, PostingDate = DateTime.Now, Rating = reviewRequest.Rating, ProductId = reviewRequest.ProductId, UserId = 1, Approved = false }; }
//[Authorize] public IHttpActionResult Post(ReviewRequest reviewRequest) { if (IsNotValid(reviewRequest)) { return this.BadRequest("Validation failed !"); } ProductReview review = CreateReviewFromRequest(reviewRequest); if (reviewService.InsertReview(review)) { return this.Created(review); } return this.InternalServerError(); }
private static bool IsNotValid(ReviewRequest review) { return review.IsNull() || review.Title.IsNullOrEmpty() || review.Comment.IsNullOrEmpty() || (review.Rating < 1 || review.Rating > 5); }