Ejemplo n.º 1
0
        public ActionResult _AddComment(int id)
        {
            var book = db.Books.Find(id);   // get book by id
            var user = db.Users.Find(System.Web.HttpContext.Current.User.Identity.GetUserId());

            var model = new ViewModels.Book.AddComment(book, user);

            return(PartialView(model));
        }
Ejemplo n.º 2
0
        public ActionResult _AddComment(ViewModels.Book.AddComment model)
        {
            if (ModelState.IsValid)
            {
                //add comment to book, save
                var comment = new Comments();

                comment.BookID  = model.BookID;
                comment.UserID  = model.UserID;
                comment.Comment = model.Comment;
                comment.Created = DateTime.UtcNow.Ticks;

                db.Comments.Add(comment);
                db.SaveChanges();

                return(RedirectToAction("Details", new { Id = model.BookID }));
            }
            return(RedirectToAction("Details", new { Id = model.BookID }));
        }