public ForGroupPanel(GroupViewItem view) { Articles = new List<ForPanel>(); this.Name = view.Name; this.IsExpanded = view.IsExpanded; this.ArticleCount = view.ArticlesCount; Articles = view.Articles.Select(c => new ForPanel { Id = c.ArticleId, Name = c.ArticleName, Rate = c.Rate}).OrderBy(c=>c.Name).ToList(); }
public ForGroupPanel(GroupViewItem view) { Articles = new List <ForPanel>(); this.Name = view.Name; this.IsExpanded = view.IsExpanded; this.ArticleCount = view.ArticlesCount; Func <IEnumerable <Tag>, string> define = (items) => { return ("[{0}]".Fmt(string.Join(",", items .OrderByDescending(c => c.Priority) .Select(c => string.Format("{0}{5}Name{5}:{5}{1}{5},{5}TagColor{5}:{5}{2}{5},{5}Priority{5}:{5}{3}{5}{4}", "{", c.Name, c.TagColor, c.Priority, "}", "'"))))); }; Articles = view.Articles.Select(c => new ForPanel { Id = c.ArticleId, Name = c.ArticleName, Rate = c.Rate, CountOfImages = c.Images.Count, CreationDate = c.CreationDate, Tags = define(c.Tags) }).OrderBy(c => c.Name).ToList(); }
public GroupView(IEnumerable <ArticleGroup> groups, IEnumerable <Article> articles) { GroupViewItems = new List <GroupViewItem>(); var lst = new List <Article>(); foreach (var articleGroup in groups) { var currentArticles = articles.Where(c => articleGroup.Groups.Contains(c.ArticleName)).ToList(); if (currentArticles.Any()) { GroupViewItems.Add(new GroupViewItem(articleGroup, currentArticles)); lst.AddRange(currentArticles); } } var withOutcurrentArticles = articles.Except(lst); if (withOutcurrentArticles.Any()) { var res = GroupViewItems.FirstOrDefault(c => c.Name == "Без группы"); if (res == null) { res = new GroupViewItem(groups.First(c => c.GroupName == "Без группы"), new List <Article>()); GroupViewItems.Add(res); } res.Articles.AddRange(withOutcurrentArticles); res.ArticlesCount = res.Articles.Count; } var withOutArticles = groups.Where(c => !GroupViewItems.Select(x => x.Name).Contains(c.GroupName)); foreach (var withOutArticle in withOutArticles) { GroupViewItems.Add(new GroupViewItem(withOutArticle, null)); } GroupViewItems = GroupViewItems.OrderBy(c => c.Name).ToList(); }
public GroupView(IEnumerable<ArticleGroup> groups, IEnumerable<Article> articles) { GroupViewItems = new List<GroupViewItem>(); var lst = new List<Article>(); foreach (var articleGroup in groups) { var currentArticles = articles.Where(c => articleGroup.Groups.Contains(c.ArticleName)).ToList(); if (currentArticles.Any()) { GroupViewItems.Add(new GroupViewItem(articleGroup, currentArticles)); lst.AddRange(currentArticles); } } var withOutcurrentArticles = articles.Except(lst); if (withOutcurrentArticles.Any()) { var res = GroupViewItems.FirstOrDefault(c => c.Name == "Без группы"); if (res == null) { res = new GroupViewItem(groups.First(c => c.GroupName == "Без группы"), new List<Article>()); GroupViewItems.Add(res); } res.Articles.AddRange(withOutcurrentArticles); res.ArticlesCount = res.Articles.Count; } var withOutArticles = groups.Where(c => !GroupViewItems.Select(x => x.Name).Contains(c.GroupName)); foreach (var withOutArticle in withOutArticles) { GroupViewItems.Add(new GroupViewItem(withOutArticle, null)); } GroupViewItems = GroupViewItems.OrderBy(c => c.Name).ToList(); }