コード例 #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
     };
 }
コード例 #2
0
 public static MvcHtmlString GravatarImg(this HtmlHelper<dynamic> helper, HttpRequestBase req,int size=128)
 {
     var userManager = req.GetOwinContext().GetUserManager<ApplicationUserManager>();
     UserAccount user = userManager.FindByName(WebPageStatic.User().Identity.Name);
     if(user==null)return new MvcHtmlString("");
     BasicGravatarLoader loader=new BasicGravatarLoader(user.Email);
     return loader.GetIconTag(size);
 }