コード例 #1
0
 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
     };
 }
コード例 #2
0
        //[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();
        }
コード例 #3
0
 private static bool IsNotValid(ReviewRequest review)
 {
     return review.IsNull() || review.Title.IsNullOrEmpty() || review.Comment.IsNullOrEmpty() ||
            (review.Rating < 1 || review.Rating > 5);
 }