public IHttpActionResult AddProduct(DTO.Review productreview) { try { if (!ModelState.IsValid) { throw new ValidationException("Invalid User", ModelState); } _sampledbContext.Reviews.Add(new Review { ReviewId = productreview.ReviewId, User = productreview.User, ProductId = productreview.ProductId, Comment = productreview.Comment }); _sampledbContext.SaveChanges(); return(Ok()); } catch (Exception ex) { return(InternalServerError(ex)); } }
public IHttpActionResult UpdateProduct(int id, DTO.Review review) { try { if (!ModelState.IsValid) { throw new ValidationException("Invalid User", ModelState); } var dbreview = _sampledbContext.Reviews.SingleOrDefault(r => r.ReviewId == id); if (dbreview != null) { dbreview.Comment = review.Comment; dbreview.ProductId = review.ProductId; dbreview.Rating = review.Rating; dbreview.User = review.User; _sampledbContext.Entry(dbreview).State = System.Data.Entity.EntityState.Modified; _sampledbContext.SaveChanges(); } return(Ok()); } catch (Exception ex) { return(InternalServerError(ex)); } }