示例#1
0
 /// <summary>
 /// 記事表示用のVMを生成するメソッド
 /// </summary>
 /// <param name="articleId"></param>
 /// <returns></returns>
 private async Task<ViewArticleViewModel> getArticleViewModel(string articleId)
 {
     ApplicationDbContext context = HttpContext.GetOwinContext().Get<ApplicationDbContext>();
     var article =  await context.Articles.FindAsync(articleId);
     if (article == null) return null;
     await context.Entry(article).Collection(c=>c.Tags).LoadAsync();
     BlobStorageConnection bConnection = new BlobStorageConnection();
     TableStorageConnection tConnection = new TableStorageConnection();
     ArticleBodyTableManager manager=new ArticleBodyTableManager(bConnection);
     ArticleThumbnailManager thumbnail=new ArticleThumbnailManager(bConnection);
     LabelTableManager ltm=new LabelTableManager(tConnection);
     ArticleCommentTableManager actm=new ArticleCommentTableManager(tConnection);
     var author =
         await
             HttpContext.GetOwinContext()
                 .GetUserManager<ApplicationUserManager>()
                 .FindByNameAsync(article.AuthorID);
     if (article.IsDraft)
     {
         if (article.AuthorID != User.Identity.Name) return null;
     }
     else
     {
         article.PageView++;
     }
     await context.SaveChangesAsync();
     IGravatarLoader gLoader = new BasicGravatarLoader(author.Email);
     int commentCount = 0;
     string commentsAsJson = actm.GetCommentsAsJson(articleId, out commentCount);
     int count = 0;
     return new ViewArticleViewModel()
     {
         ArticleId = articleId,
         Author=author.NickName,
         Author_ID=author.UniqueId,
         Author_IconTag=gLoader.GetIconTag(50),
         PageView=article.PageView,
         Title = article.Title,
         Content =await manager.GetArticleBody(article.ArticleModelId),
         LabelInfo=ltm.GetLabelsJson(articleId),
         Tags =await getArticleTagModels(article),
         LabelCount = article.LabelCount,
         Article_Date = article.CreationTime.ToShortDateString(),
         Article_UpDate = article.UpdateTime.ToShortDateString(),
         UseThumbnail= thumbnail.CheckThumbnailExist(articleId),
         CommentInfo=commentsAsJson,
         CommentCount=commentCount,
         RelatedArticles=getRelatedArticles(context,0,0,article,3),
         AuthorsArticles=getUserArticles(context,0,0,article.AuthorID,out count,takeCount: 3,exceptId:article.ArticleModelId),
         IsPreview=false
     };
 }
        public async Task<IHttpActionResult> ArticleRankingJob(CronRequest req)
        {
//            if (CronRequest.IsCronRequest(req))
//            {
                var context = Request.GetOwinContext().Get<ApplicationDbContext>();
                TableStorageConnection tConnection = new TableStorageConnection();
                StatisticsLogModel logModel = StatisticsLogModel.CreateNewModel();
            StatisticsLogModel lastLog = context.StatisticsLog.OrderByDescending(f => f.JobTime).Take(1).FirstOrDefault();
            context.StatisticsLog.Add(logModel);
            await context.SaveChangesAsync();
                ArticleStatisticsBasicManager asbm=new ArticleStatisticsBasicManager(tConnection);
                await asbm.InsertArticleLog(context, logModel.Key, lastLog==null?"":lastLog.Key);
                return Json(true);
//            }
//            else
//            {
//                return Json(false);
//            }
        }