public void AddComment(Comment comment)
 {
     using (var db = new BlogContext())
     {
         comment.CreationDate = DateTime.UtcNow;
         db.Comments.Add(comment);
         db.SaveChanges();
     }
 }
Пример #2
0
 public ActionResult Blog(int id, Comment newComment)
 {
     if (ModelState.IsValid)
     {
         newComment.blog = _db.Blogs.Find(id);
         _db.Comments.Add(newComment);
         _db.SaveChanges();
         return RedirectToAction("Blog", new { Id = id });
     }
     var blog = _db.Blogs.Find(id);
     return View(blog);
 }
 public Comment RetriveComments(Comment comment)
 {
     using (var db = new BlogContext())
     {
         List<Comment> comments = new List<Comment>();
         var dbComment = db.Comments.Include(x => x.Author).Include(c => c.Comments).Where(c => c.Id == comment.Id).FirstOrDefault();
         foreach (var item in dbComment.Comments)
         {
             comments.Add(RetriveComments(item));
         }
         dbComment.Comments = comments;
         return dbComment;
     }
 }
        public ActionResult CommentComment(Comment comment, string Command)
        {
            try
            {
                if (Command.Equals("MarkAsRead", StringComparison.InvariantCultureIgnoreCase))
                {
                    commentManager.MarkAsRead(comment.ParentId.Value);
                }
                else
                {
                    var user = (User)Session["Login"];

                    var newComment = new Comment();
                    newComment.Text = comment.Text;
                    newComment.ArticleId = comment.ArticleId;
                    newComment.ParentId = comment.ParentId;

                    commentManager.AddComment(newComment);
                    userManager.UpdateUserComments(user.Id, newComment);
                    commentManager.MarkAsRead(comment.ParentId.Value);
                }

                return RedirectToAction("UnreadComments");
            }
            catch (Exception e)
            {
                ViewBag.ErrorTitle = "Server Error";
                ViewBag.ErrorDescription = "Please try again later";
                return View("~/Views/Shared/ErrorPage.cshtml");
            }
        }
        public ActionResult CommentArticle(Comment comment)
        {
            try
            {
                var user = (User)Session["Login"];

                if (comment != null || !String.IsNullOrWhiteSpace(comment.Text))
                {
                    commentManager.AddComment(comment);

                    userManager.UpdateUserComments(user.Id, comment);
                }

                return RedirectToAction("ArticleView", new { id = comment.ArticleId });
            }
            catch (Exception e)
            {
                ViewBag.ErrorTitle = "Server Error";
                ViewBag.ErrorDescription = "Please try again later";
                return View("~/Views/Shared/ErrorPage.cshtml");
            }
        }
        public ActionResult AddComment(Comment comment)
        {
            try
            {
                var user = (User)Session["Login"];

                var newComment = new Comment();
                newComment.Text = comment.Text;
                newComment.ArticleId = comment.ArticleId;
                newComment.ParentId = comment.ParentId;

                commentManager.AddComment(newComment);
                userManager.UpdateUserComments(user.Id, newComment);

                return RedirectToAction("ArticleView", new { id = comment.ArticleId });
            }
            catch (Exception e)
            {
                ViewBag.ErrorTitle = "Server Error";
                ViewBag.ErrorDescription = "Please try again later";
                return View("~/Views/Shared/ErrorPage.cshtml");
            }
        }
Пример #7
0
 public void AddComment(Comment comment)
 {
     context.Comments.Add(comment);
     context.SaveChanges();
 }
Пример #8
0
        public void UpdateUserComments(int userId, Comment comment)
        {
            using (var db = new BlogContext())
            {
                db.Comments.Attach(comment);
                var query = (from u in db.Users.Include(u => u.Comments)
                             where u.IsActive == true && u.Id == userId
                             select u).FirstOrDefault<User>();

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