Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // GET: Article/{slug}
- public ActionResult Index(string slug)
- {
- ApplicationDbContext Context = new ApplicationDbContext();
- var Article = Context.Articles.FirstOrDefault(x => x.Slug == slug);
- if (Article != null)
- {
- List<Comment> Comments = Context.Comments.Where(x => x.ArticleId == Article.Id).ToList();
- List<ReadCommentViewModel> _Comments = new List<ReadCommentViewModel>();
- foreach (Comment Comment in Comments)
- {
- _Comments.Add(new ReadCommentViewModel { Author = Comment.Author, Content = Comment.Content, DateString = Comment.Date.Humanize(true, DateTime.UtcNow), Id = Comment.Id });
- }
- Markdown Markdown = new Markdown();
- ReadArticleViewModel Model = new ReadArticleViewModel
- {
- Author = Article.Author,
- Comments = _Comments,
- Content = Markdown.Transform(Article.Content),
- DateString = Article.Date.Humanize(true, DateTime.UtcNow),
- Id = Article.Id,
- ImagePath = Article.ImagePath,
- Slug = Article.Slug,
- Title = Article.Title
- };
- return View(Model);
- }
- else
- {
- return View();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement