Exemplo n.º 1
0
        public ActionResult ShowAll()
        {
            using (var db = new BlogDbContext())
            {
                var posts = db.Posts.Where(p => p.IsDeleted == false).OrderByDescending(p => p.PublishDate)
                            .ToList();
                posts = GetMethods.GetInitializedUserList(posts);
                ViewData["Layout"] = GetMethods.GetLayout(User.Identity.Name);

                return(View("~/Views/Main/AllPosts.cshtml", posts));
            }
        }
Exemplo n.º 2
0
 public ActionResult Profile()
 {
     using (var db = new BlogDbContext())
     {
         var login     = User.Identity.Name;
         var userId    = db.Users.Where(u => u.Username.Equals(login)).Select(u => u.UserId).FirstOrDefault();
         var userPosts = db.Posts.Where(p => p.UserId == userId && p.IsDeleted == false)
                         .OrderByDescending(p => p.PublishDate).ToList();
         userPosts          = GetMethods.GetInitializedUserList(userPosts);
         ViewData["Layout"] = GetMethods.GetLayout(login);
         return(View("~/Views/User/Profile.cshtml", userPosts));
     }
 }
Exemplo n.º 3
0
        public ActionResult ShowPost(int postId)
        {
            using (var db = new BlogDbContext())
            {
                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));
            }
        }
Exemplo n.º 4
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));
            }
        }