Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. // GET: Article/{slug}
  2. public ActionResult Index(string slug)
  3. {
  4.     ApplicationDbContext Context = new ApplicationDbContext();
  5.  
  6.     var Article = Context.Articles.FirstOrDefault(x => x.Slug == slug);
  7.  
  8.     if (Article != null)
  9.     {
  10.         List<Comment> Comments = Context.Comments.Where(x => x.ArticleId == Article.Id).ToList();
  11.         List<ReadCommentViewModel> _Comments = new List<ReadCommentViewModel>();
  12.         foreach (Comment Comment in Comments)
  13.         {
  14.             _Comments.Add(new ReadCommentViewModel { Author = Comment.Author, Content = Comment.Content, DateString = Comment.Date.Humanize(true, DateTime.UtcNow), Id = Comment.Id });
  15.         }
  16.  
  17.         Markdown Markdown = new Markdown();
  18.         ReadArticleViewModel Model = new ReadArticleViewModel
  19.         {
  20.             Author = Article.Author,
  21.             Comments = _Comments,
  22.             Content = Markdown.Transform(Article.Content),
  23.             DateString = Article.Date.Humanize(true, DateTime.UtcNow),
  24.             Id = Article.Id,
  25.             ImagePath = Article.ImagePath,
  26.             Slug = Article.Slug,
  27.             Title = Article.Title
  28.         };
  29.  
  30.         return View(Model);
  31.     }
  32.     else
  33.     {
  34.         return View();
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement