public IActionResult EditPost(int postId) { var loadPost = _postProcessor.LoadPostById(postId).FirstOrDefault(); PostDisplayModel post = new PostDisplayModel { Id = loadPost.Id, AuthorName = loadPost.AuthorName, Title = loadPost.Title, Content = loadPost.Content, CreatedDate = loadPost.CreatedDate, CategoryName = loadPost.CategoryName }; return(View(post)); }
public IActionResult ViewPost(int postId) { var loadPost = _postProcessor.LoadPostById(postId).FirstOrDefault(); var loadComments = _commentProcessor.LoadComments(postId).OrderByDescending(x => x.CreatedDate); PostDisplayModel post = new PostDisplayModel { Id = loadPost.Id, AuthorName = loadPost.AuthorName, Title = loadPost.Title, Content = loadPost.Content, CreatedDate = loadPost.CreatedDate, CategoryName = loadPost.CategoryName }; List <CommentDisplayModel> commentList = new List <CommentDisplayModel>(); foreach (var comment in loadComments) { CommentDisplayModel model = new CommentDisplayModel { Id = comment.Id, PostId = comment.PostId, UserName = comment.UserName, Content = comment.Content, CreatedDate = comment.CreatedDate }; commentList.Add(model); } post.Comments = commentList; //PostModel post = new PostModel //{ // Id = load.Id, // AuthorId = load.AuthorId, // Title = load.Title, // Content = load.Content, // CreatedDate = load.CreatedDate, // CategoryId = load.CategoryId //}; return(View(post)); }
public IActionResult EditPost(PostDisplayModel model) { _postProcessor.EditPost(model.Id, model.Title, model.Content); return(RedirectToAction("Index", "Home")); }