public ActionResult AddComment(Comment comment) { if (ModelState.IsValid) { comment.CommentTime = DateTime.Now; db.Comments.Add(comment); db.SaveChanges(); } return(Json(new { })); }
public async Task <ActionResult> book(int id) { Book book = await db.Books.FindAsync(id); if (book == null) { return(HttpNotFound()); } if (Request.Cookies["ViewedPage"] != null) { if (Request.Cookies["ViewedPage"][string.Format("bId_{0}", book.Id)] == null) { HttpCookie cookie = Request.Cookies["ViewedPage"]; cookie[string.Format("bId_{0}", book.Id)] = book.Id.ToString(); cookie.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(cookie); book.ViewCount = book.ViewCount + 1; db.SaveChanges(); } } return(View(book)); }