Esempio n. 1
0
        public ActionResult Detail(int id)
        {
            var article = _articleService.GetArticleById(id);

            article.Views++;
            _articleService.UpdateArticle(article);

            var model = new ArticleDetailModel();

            model.Article = new ArticleModel
            {
                Id               = article.Id,
                Title            = article.Title,
                Author           = "NextCMS",
                PictureCoverImg  = _pictureService.GetPictureUrl(article.PictureId, 500, true),
                Views            = article.Views,
                CommentCount     = article.CommentCount,
                ShortDescription = article.ShortDescription,
                FullDescription  = article.FullDescription,
                CreateDate       = WebHelper.ConvertToUserTime(article.CreateDate)
            };

            if (article.Category != null)
            {
                model.Article.CategoryId   = article.CategoryId.Value;
                model.Article.CategoryName = article.Category.Name;
            }

            return(View(model));
        }
Esempio n. 2
0
        public IActionResult ArticleDetail(int id)
        {
            var now = DateTime.Now;

            var model = new ArticleDetailModel();

            model.Article           = new Article();
            model.Article.StartedOn = now;
            model.Article.StoppedOn = now.AddDays(5);

            if (id > 0)
            {
                model.Article = DefaultStorage.ArticleGet(id);
            }
            return(View(model));
        }
Esempio n. 3
0
        private IModel Read(Dictionary <string, object> r)
        {
            var m = new ArticleDetailModel();

            // 开始赋值
            var          type = typeof(ArticleDetailModel);
            var          guid = new Guid(r["cID"].ToString());
            PropertyInfo pi   = type.BaseType.GetProperty("ID");

            pi.SetValue(m, guid);

            m.ArticleID = new Guid(r["cArticleID"].ToString());
            m.AnswerNo  = r["cAnswerNo"].ToString();
            m.Title     = r["cTitle"].ToString();

            return(m);
        }
Esempio n. 4
0
        // GET: Article
        public ActionResult Index(string name)
        {
            var article = db.Articles.SingleOrDefault(a => a.UrlKeyword.Equals(name));

            if (article == default(Article))
            {
                return(HttpNotFound());
            }
            var catalog      = article.Catalogs.FirstOrDefault();
            var releatedList = catalog.Articles.Where(a => a.Publish && a.PublishedDate >= article.PublishedDate).OrderBy(a => a.PublishedDate).Take(3).OrderByDescending(a => a.PublishedDate).ToList();

            releatedList.AddRange(catalog.Articles.Where(a => a.Publish && a.PublishedDate < article.PublishedDate).OrderByDescending(a => a.PublishedDate).Take(10).ToList());

            var data = new ArticleDetailModel
            {
                Article          = article,
                Catalog          = catalog,
                ReleatedArticles = releatedList
            };

            return(View(data));
        }
Esempio n. 5
0
 public ActionResult ArticleViewer(ArticleDetailModel model)
 {
     model.ArticleUrl = Url.CurrentUrl();
     return(PartialView(model));
 }
Esempio n. 6
0
        /// <summary>
        /// 文章详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <IActionResult> Detail(int id)
        {
            if (id == 0)
            {
                return(new NotFoundViewResult());
            }

            Article article = await _dbContext.Article.Where(s => s.Status == (int)CommonStatus.Valid)
                              .Include(s => s.Remarks).ThenInclude(s => s.User)
                              .Include(s => s.Remarks).ThenInclude(s => s.RemarkReplys).ThenInclude(s => s.User)
                              .Include(s => s.Remarks).ThenInclude(s => s.RemarkReplys).ThenInclude(s => s.TargetUser)
                              .Include(s => s.ArticleMusics).ThenInclude(s => s.Music)
                              .FirstOrDefaultAsync(s => s.Id == id);

            if (article == null)
            {
                return(new NotFoundViewResult());
            }

            ArticleDetailModel detailModel = new ArticleDetailModel();

            detailModel.Article = article;

            detailModel.ArticleCategorys = await _dbContext.Set <ArticleCategory>().ToListAsync();

            detailModel.RandomArticles = await _dbContext.Article
                                         .Where(s => s.Status == (int)CommonStatus.Valid)
                                         .Select(s => new Article()
            {
                Id         = s.Id,
                CreateTime = s.CreateTime,
                Title      = s.Title
            })
                                         .OrderBy(s => Guid.NewGuid())
                                         .Take(8)
                                         .ToListAsync();

            var similarArticles = await _dbContext.Article
                                  .Where(s => s.Status == (int)CommonStatus.Valid && s.Id != article.Id)
                                  .Select(s => new Article()
            {
                Id         = s.Id,
                CreateTime = s.CreateTime,
                Title      = s.Title
            })
                                  .ToListAsync();

            //筛选相似数据
            similarArticles = similarArticles.Where(s => StringSimilarity.Calculate(article.Title, s.Title) > 0.3m).OrderBy(s => Guid.NewGuid()).Take(8).ToList();

            detailModel.SimilarArticles = similarArticles;

            string viewCountStr = await _cache.GetStringAsync($"article{id}");

            if (viewCountStr.IsNullOrEmpty())
            {
                viewCountStr = "0";
            }
            int viewCount = int.Parse(viewCountStr) + 1;
            await _cache.SetStringAsync($"article{id}", viewCount.ToString());

            article.ReadCount += viewCount;
            if (viewCount == int.Parse(Configuration["AppSettings:Threshold"]))
            {
                _dbContext.Set <Article>().Update(article);
                if (await _dbContext.SaveChangesAsync() <= 0)
                {
                    _logger.LogWarning($"更新文章浏览量失败,ID:{article.Id}");
                }
                await _cache.RemoveAsync($"article{id}");
            }

            return(View(detailModel));
        }