public HttpResponseMessage GetOneReview(HttpRequestMessage request, ReviewViewID reviewID) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; Review review = service.getOneReview(reviewID.ID, reviewID.userID); if (review != null) { ReviewView obj = new ReviewView(); obj.reviewText = review.reviewText; obj.userID = review.userID; obj.bookID = review.bookID; obj.ID = review.ID; obj.ratingScore = 0; obj.addedTime = review.addedTime; UserDataNoPass usr = servUs.getUserAfterID(obj.userID); if (usr != null) { obj.user = usr; } else { obj.user = new UserDataNoPass(); } RatingView rati = servRat.getRating(obj.bookID, obj.userID); if (rati != null) { obj.ratingScore = rati.ratingScore; obj.rating = rati; } else { obj.ratingScore = 0; } response = request.CreateResponse(HttpStatusCode.OK, obj, JsonMediaTypeFormatter.DefaultMediaType); } else { ReviewView rev = new ReviewView(); response = request.CreateResponse(HttpStatusCode.OK, rev, JsonMediaTypeFormatter.DefaultMediaType); } unitOfWork.Commit(); return response; })); }
public HttpResponseMessage DeleteReview(HttpRequestMessage request, ReviewViewID reviewID) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; bool wasDeleted = service.deleteReview(reviewID.ID); bool wasDeletedRating = servRat.deleteRating(reviewID.userID); if (wasDeleted && wasDeletedRating) { response = request.CreateResponse(HttpStatusCode.OK, true); } else { response = request.CreateResponse(HttpStatusCode.OK, false); } unitOfWork.Commit(); return response; })); }