/// <summary> /// Get Stats from all entities in Model /// </summary> /// <returns>DTO object with the Stats</returns> public StatsDTO RetrieveBlogStats() { StatsDTO model = new StatsDTO(); model.TotalPosts = PostRepository.GetCount(); model.TotalTags = TagRepository.GetCount(); model.TotalAlbums = AlbumRepository.GetCount(); model.TotalCategories = CategoryRepository.GetCount(); model.TotalImages = ImageRepository.GetCount(); model.TotalUsers = UserRepository.GetCount(); model.TotalComments = CommentRepository.GetCount(); model.TotalRoles = RoleRepository.GetCount(); model.TopRatedPosts = PostRepository.Get(p => p.Ratings.Any(), o => o.OrderByDescending(p => p.Ratings.Average(r => r.Value)), "Ratings").Take(10); model.MostVisitedPosts = PostRepository.Get(p=>p.Visits > 0, o => o.OrderByDescending(p => p.Visits)).Take(10); model.MostCommentedPosts = PostRepository.Get(p => p.Comments.Any(), o => o.OrderByDescending(c => c.Comments.Count()), "Comments").Take(10); model.PostWritenByUser = UserRepository.Get(u => u.Roles.Any(r => r.RoleName == "admin")); return model; }
/// <summary> /// Get Stats for Sidebar Widget /// </summary> /// <returns>DTO object with the Stats</returns> public StatsDTO RetrieveSidebarStats(bool ispremium) { StatsDTO model = new StatsDTO(); if (ispremium) { model.TopRatedPosts = PostRepository.Get(p => p.Ratings.Any() && p.IsAboutMe == false, o => o.OrderByDescending(p => p.Ratings.Average(r => r.Value)), "Ratings").Take(10); model.MostVisitedPosts = PostRepository.Get(p => p.Visits > 0 && p.IsAboutMe == false, o => o.OrderByDescending(p => p.Visits)).Take(10); model.MostCommentedPosts = PostRepository.Get(p => p.Comments.Any() && p.IsAboutMe == false, o => o.OrderByDescending(c => c.Comments.Count()), "Comments").Take(10); } else { model.TopRatedPosts = PostRepository.Get(p => p.Ratings.Any() && p.IsPublic && p.IsAboutMe == false, o => o.OrderByDescending(p => p.Ratings.Average(r => r.Value)), "Ratings,Image").Take(10); model.MostVisitedPosts = PostRepository.Get(p => p.Visits > 0 && p.IsPublic && p.IsAboutMe == false, o => o.OrderByDescending(p => p.Visits), "Image").Take(10); model.MostCommentedPosts = PostRepository.Get(p => p.Comments.Any() && p.IsPublic && p.IsAboutMe == false, o => o.OrderByDescending(c => c.Comments.Count()), "Comments,Image").Take(10); } return model; }