public static List<SearchResultArticle> getRelatedArticles(ApplicationDbContext context, int order, int skip, ArticleModel article, int count) { ArticleThumbnailManager thumbnailManager = new ArticleThumbnailManager(new BlobStorageConnection()); //直接の関係の記事を探す IQueryable<ArticleModel> query = context.Articles.Where(f => f.RelatedArticleId.Equals(article.ArticleModelId)); query = ChangeOrder(order, query); query = query.Skip(skip); List<SearchResultArticle> articles = new List<SearchResultArticle>(); foreach (var source in query.Take(count)) { articles.Add(new SearchResultArticle() { ArticleId = source.ArticleModelId, LabelCount = source.LabelCount, PageView = source.PageView, Title = source.Title, Article_UpDate = source.UpdateTime.ToShortDateString(), ThumbnailTag = thumbnailManager.GenerateThumnailTag(source.ArticleModelId) }); } int remain = count - article.LabelCount; if(article.LabelCount<count) {//取り出すカウントに満たない場合は間接的関連記事でうめる context.Articles.Where(f => f.ThemeId.Equals(article.ThemeId)&&!f.RelatedArticleId.Equals(article.ArticleModelId)); query = ChangeOrder(order, query); query = query.Skip(skip); foreach (var source in query.Take(remain)) { articles.Add(new SearchResultArticle() { ArticleId = source.ArticleModelId, LabelCount = source.LabelCount, PageView = source.PageView, Title = source.Title, Article_UpDate = source.UpdateTime.ToShortDateString(), ThumbnailTag = thumbnailManager.GenerateThumnailTag(source.ArticleModelId) }); } } return articles; }
public ArticleSummaryResponse(ArticleModel model,LabelTableManager ltm) { this.Title = model.Title; this.LabelCount = model.LabelCount; this.LabelInfo = ltm.GetLabelsJson(model.ArticleModelId); }
private async Task<IEnumerable<TagViewModel>> getArticleTagModels(ArticleModel article) { ApplicationDbContext context = HttpContext.GetOwinContext().Get<ApplicationDbContext>(); int tagCount = article.Tags.Count; var tagVms = new TagViewModel[tagCount]; int count = 0; foreach (var tagRef in article.Tags) { await context.Entry(tagRef).Collection(c => c.Articles).LoadAsync(); tagVms[count] = new TagViewModel() { ArticleCount = tagRef.Articles.Count, TagId = tagRef.ArticleTagModelId, TagName = tagRef.TagName, IsTheme = tagRef.IsThemeTag }; count++; } return tagVms; }