public IHttpActionResult PutCommentProduct(int id, CommentProduct commentProduct) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != commentProduct.CommentID) { return(BadRequest()); } db.Entry(commentProduct).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CommentProductExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PostCommentProduct(CommentProduct commentProduct) { db.CommentProducts.Add(commentProduct); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = commentProduct.CommentID }, commentProduct)); }
public async Task <ActionResult> Comment(int productID, string message, int rating) { var currentUser = await _userManager.GetUserAsync(User); if (currentUser == null) { return(Challenge()); } if (!string.IsNullOrEmpty(message)) { Comment comment = new Comment() { Message = message, Status = 1, UserID = currentUser.UserName, CommentTime = DateTime.Now, rating = rating != 0 ? rating : 0, }; _context.Add(comment); _context.SaveChanges(); CommentProduct commentProduct = new CommentProduct() { CommentID = comment.CommentID, ProductID = productID, }; _context.Add(commentProduct); _context.SaveChanges(); await _context.SaveChangesAsync(); } return(Redirect(Request.Headers["Referer"].ToString())); }
public IHttpActionResult DeleteCommentProduct(int id) { CommentProduct commentProduct = db.CommentProducts.Find(id); if (commentProduct == null) { return(NotFound()); } db.CommentProducts.Remove(commentProduct); db.SaveChanges(); return(Ok(commentProduct)); }