public ActionResult CreateComment(int bookId, string body) { Book book = db.Books.FirstOrDefault(b => b.BookID == bookId); if (book == null) { return RedirectToAction("NotFound", "Error", new { message = "Книга не найдена." }); } BookComment comment = new BookComment { AddedBy = User.Identity.Name, AddedByIP = Request.UserHostAddress, AddedDate = DateTime.Now, Body = body.AntiRudeFilter() }; book.BookComments.Add(comment); db.SaveChanges(); return Json(new { commentId = comment.BookCommentID, name = comment.AddedBy, body = comment.Body }); }
/// <summary> /// Deprecated Method for adding a new object to the BookComments EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToBookComments(BookComment bookComment) { base.AddObject("BookComments", bookComment); }
/// <summary> /// Create a new BookComment object. /// </summary> /// <param name="bookCommentID">Initial value of the BookCommentID property.</param> /// <param name="addedDate">Initial value of the AddedDate property.</param> /// <param name="addedBy">Initial value of the AddedBy property.</param> /// <param name="addedByIP">Initial value of the AddedByIP property.</param> /// <param name="bookID">Initial value of the BookID property.</param> /// <param name="body">Initial value of the Body property.</param> public static BookComment CreateBookComment(global::System.Int32 bookCommentID, global::System.DateTime addedDate, global::System.String addedBy, global::System.String addedByIP, global::System.Int32 bookID, global::System.String body) { BookComment bookComment = new BookComment(); bookComment.BookCommentID = bookCommentID; bookComment.AddedDate = addedDate; bookComment.AddedBy = addedBy; bookComment.AddedByIP = addedByIP; bookComment.BookID = bookID; bookComment.Body = body; return bookComment; }