public IActionResult Info(int Id) { BookComments model = new BookComments { Book = db.Books.First(b => b.Id == Id), Comments = db.Comments.Where(c => c.BookId == Id) }; return(View(model)); }
public async Task <IActionResult> Book(int id) { BookComments currentBook = new BookComments { Book = await _db.Books.Include(p => p.Author).Include(p => p.Genre).FirstOrDefaultAsync(p => p.Id == id) }; if (currentBook.Book != null) { currentBook.Comments = await _db.Comments.Where(i => i.BookId == id).Include(i => i.User).OrderByDescending(i => i.PublicationDate).ToListAsync(); return(View(currentBook)); } return(NotFound()); }
public ActionResult CommentBook(int id, string _point, string _comment) { try { Books book = db.Books.Find(id); User user = db.Users.Where(x => x.USERNAME == User.Identity.Name).FirstOrDefault(); BookComments new_comment = new BookComments(); new_comment.BOOK = book; new_comment.USER = user; new_comment.COMMENT = _comment; new_comment.POINT = Convert.ToInt32(_point); db.BookComments.Add(new_comment); db.SaveChanges(); return(RedirectToAction("TheBook", "Book", new { id = book.BOOK_ID })); } catch (Exception) { return(HttpNotFound()); } }
public async Task <IActionResult> AddComment([FromRoute(Name = "id")] int id, BookComments bookComments) { if (bookComments.NewComment.Content.Length > 3) { _db.Comments.Add(new Comment { UserId = _db.Users.Where(i => i.Email == User.Identity.Name).Select(i => i.Id).FirstOrDefault(), Content = bookComments.NewComment.Content, PublicationDate = DateTime.Now, BookId = id }); await _db.SaveChangesAsync(); } else { ModelState.AddModelError("NewComment.Content", "Комментарий слишком короткий!"); } return(RedirectToAction("Book", new { id = id })); }