public GroupsViewModel GetGroupsViewModel(IEnumerable<int> groupIds) { IEnumerable<Group> grs = (groupIds == null ? Db.Groups.Where(g => g.Entries.Count > 0) : Db.Groups.Where(g => groupIds.Contains(g.Id) && g.Entries.Count > 0)).ToList(); var model = new GroupsViewModel { Groups = new List<GroupViewModel>() }; var fetch = Db.Entries.ToList(); foreach (var gr in grs) { var g = new GroupViewModel { Name = gr.Name, Id = gr.Id }; model.Groups.Add(g); g.Entries = fetch.Where(f => f.Group == gr).OrderByDescending(d => d.Date).Take(WebConfig.HomeViewItemPerGroup).Select(EntryViewModel.FromEntry).ToList(); //g.Entries = gr.Entries.Take(WebConfig.HomeViewItemPerGroup).Select(EntryViewModel.FromEntry).ToList(); } return model; }
public static GroupViewModel SampleGroupViewModel(string name) { var op = new GroupViewModel { Name = name, BreadCrumbItems = new List<string> { "Technology", "Science" }, Entries = new List<EntryViewModel>(), EntryCount = 10000, Id = -1 }; op.Entries.Add(new EntryViewModel { Title = "RenderType1", PostedDate = DateTime.Now, RenderType = "RenderType1" }); op.Entries.Add(new EntryViewModel { Title = "RenderType2", PostedDate = DateTime.Now, RenderType = "RenderType2" }); op.Entries.Add(new EntryViewModel { Title = "RenderType2", PostedDate = DateTime.Now, RenderType = "RenderType3" }); op.Entries.Add(new EntryViewModel { Title = "RenderType2", PostedDate = DateTime.Now, RenderType = "RenderType4" }); for (var i = 0; i < 20; i++) { op.Entries.Add(new EntryViewModel { Title = "Entry " + i, PostedDate = DateTime.Now }); } return op; }