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)); } }
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)); } }
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)); } }
public ActionResult OpenUserUpdatePost(int postid) { using (BlogDbContext db = new BlogDbContext()) { var username = User.Identity.Name; if (CheckMethods.IsUsersPost(postid, username)) { ViewData["Layout"] = GetMethods.GetLayout(User.Identity.Name); var post = db.Posts.FirstOrDefault(p => p.PostId == postid); return(View("~/Views/User/UserUpdatePost.cshtml", post)); } return(RedirectToAction("AccessDenied", "Error")); } }
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)); } }
public ActionResult OpenAddPost() { ViewData["Layout"] = GetMethods.GetLayout(User.Identity.Name); return(View("~/Views/User/NewPost.cshtml")); }