Beispiel #1
0
        public ActionResult UserDeleteComment(int postId, int commentId)
        {
            string username = User.Identity.Name;
            var    userId   = GetMethods.GetUserId(username);

            if (CheckMethods.IsUsersComment(userId, commentId))
            {
                DeleteComment(commentId);
                return(RedirectToAction("ShowPost", "MainPage", new { postId = postId }));
            }
            return(RedirectToAction("AccessDenied", "Error"));
        }
Beispiel #2
0
        public ActionResult UserUpdateComment(int postId, int commentId)
        {
            using (BlogDbContext db = new BlogDbContext())
            {
                string username = User.Identity.Name;
                var    userId   = GetMethods.GetUserId(username);
                if (!CheckMethods.IsUsersComment(userId, commentId))
                {
                    return(RedirectToAction("AccessDenied", "Error"));
                }
                string commentToUpdate = db.Comments.Where(c => c.CommentId == commentId).Select(c => c.Content).FirstOrDefault();
                ViewBag.CommentToUpdate = commentToUpdate;
                var post     = db.Posts.FirstOrDefault(p => p.PostId == postId);
                var user     = db.Users.FirstOrDefault(u => u.UserId == post.UserId);
                var comments = db.Comments.Where(c => c.PostId == postId).ToList();
                comments     = GetMethods.GetInitializedUserList(comments);
                ViewBag.User = user;

                ViewBag.Comments   = comments;
                ViewData["Layout"] = GetMethods.GetLayout(User.Identity.Name);
                return(View("~/Views/Main/ShowPost.cshtml", post));
            }
        }