public string AddReview(string prodId, ProductService.Model.Review review) { review.Id = ObjectId.GenerateNewId().ToString(); review.ProdId = prodId; review.ReviewDate = DateTime.UtcNow; MongoHelper.ReviewsCollection.Insert(review); return(review.Id); }
public HttpResponseMessage AddProductReview(string prodId, Review review) { IProductRepository repository = RepositoryHelper.GetRepository(); var reviewId = repository.AddReview(prodId, review); var responseMsg = Request.CreateResponse(HttpStatusCode.Created); // Set location header such that anything passed after the action "review" is discarded. var locationUri = Request.RequestUri.ToString(); var actionIndex = locationUri.IndexOf("review", StringComparison.CurrentCultureIgnoreCase); if (actionIndex != -1) responseMsg.Headers.Location = new Uri(locationUri.Substring(0, actionIndex) + "review/" + reviewId); return responseMsg; }
public bool UpdateReview(string reviewId, ProductService.Model.Review review) { ObjectId objectId; if (ObjectId.TryParse(reviewId, out objectId)) { var query = Query <Review> .EQ(r => r.Id, objectId.ToString()); var updates = Update <Review> .Combine( Update <Review> .Set(r => r.ReviewDate, DateTime.UtcNow), Update <Review> .Set(r => r.Rating, review.Rating), Update <Review> .Set(r => r.Comments, review.Comments)); var result = MongoHelper.ReviewsCollection.Update(query, updates); return(result.Ok); } else { return(false); } }
public bool UpdateReview(string reviewId, Review review) { var reviewIndex = reviews.FindIndex(r => r.Id == reviewId); if (reviewIndex >= 0) { reviews[reviewIndex].Comments = review.Comments; reviews[reviewIndex].Rating = review.Rating; reviews[reviewIndex].ReviewDate = DateTime.Now; } return (reviewIndex >= 0); }
public string AddReview(string prodId, Review review) { review.Id = ""; // Make sure the product exists if (products.Exists(p => p.Id == prodId)) { review.ProdId = prodId; review.Id = (++nextReviewId).ToString(); review.ReviewDate = DateTime.Now; reviews.Add(review); } return review.Id; }
public HttpResponseMessage UpdateReview(string prodId, string reviewId, Review review) { IProductRepository repository = RepositoryHelper.GetRepository(); var existingReview = repository.GetReview(reviewId); if ((existingReview != null) && (existingReview.ProdId == prodId)) if (repository.UpdateReview(reviewId, review)) { var responseMsg = Request.CreateResponse(HttpStatusCode.Created); responseMsg.Headers.Location = Request.RequestUri; return responseMsg; } else return Request.CreateErrorResponse( HttpStatusCode.NotFound, string.Format("Review Id {0} not found.", reviewId)); else return Request.CreateErrorResponse( HttpStatusCode.NotFound, string.Format("Review Id {0} for Product Id {1} not found.", reviewId, prodId)); }