示例#1
0
        public async Task <IActionResult> AjaxGetComments(int id)
        {
            var comments = await _commentController.GetAllCommentsAsync(id);

            var jsonString = JsonConvert.SerializeObject(comments);

            return(Content(jsonString, "application/json"));
        }
示例#2
0
        public async Task <IActionResult> About()
        {
            var article = await _context.Article.OrderByDescending(a => a.AddTime)
                          .FirstOrDefaultAsync(m => m.Title == "「LONEFIRE」关于");

            if (article == null)
            {
                article = new Article();
                _toaster.ToastWarning("暂时没有 关于我 的内容");
            }
            ViewData["Comments"] = await _commentController.GetAllCommentsAsync(article.ArticleID);

            return(View(article));
        }
        public async Task <IActionResult> ArticleView(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var article = await _context.Article
                          .SingleOrDefaultAsync(m => m.ArticleID == id);

            if (article == null)
            {
                return(NotFound());
            }

            //Get Comments
            ViewData["Comments"] = await _commentController.GetAllCommentsAsync(article.ArticleID);

            article.ViewCount++;
            await _context.SaveChangesAsync();

            article.Content = LF_MarkdownParser.Parse(article.Content, ImageUploadPath + article.Title + '/');

            article.Author = await _userController.GetNickNameAsync(article.Author);

            ViewData["HeaderImg"] = ImageUploadPath + article.Title + '/' + article.HeaderImg;

            try
            {
                var articles = await _context.Article
                               .Where(a => !a.Title.Contains("「LONEFIRE」") && a.Status == ArticleStatus.Approved)
                               .OrderByDescending(a => a.AddTime)
                               .Select(a => new { a.ArticleID, a.Title, a.Author, a.Tag, a.AddTime, a.Status })
                               .ToListAsync();

                int idx = articles.FindIndex(a => a.ArticleID == id);

                if (articles.Count > 1)
                {
                    if (idx == 0)
                    {
                        ViewData["Next"] = articles[idx + 1];
                    }
                    else if (idx == articles.Count - 1)
                    {
                        ViewData["Prev"] = articles[idx - 1];
                    }
                    else
                    {
                        ViewData["Prev"] = articles[idx - 1];
                        ViewData["Next"] = articles[idx + 1];
                    }
                }
            }
            catch (Exception)
            {
                _toaster.ToastError("读取文章列表失败");
            }

            ViewData["Related"] = await GetRelatedArticles(article);

            return(View(article));
        }