public Response <List <Post> > GetPostsPaginationByStatusAndCategory(int offset, int maxAmount, string status, int categoryId) { var r = new Response <List <Post> >(); try { r.Success = true; r.Message = "Loaded posts."; r.Data = _postRepo.GetPostsPaginationByStatusAndCategory(offset, maxAmount, status, categoryId); foreach (Post p in r.Data) { p.CategoriesOnPost = _categoryOnPostRepo.GetAllCategoriesForPost(p.Id); p.TagsOnPost = _tagOnPostRepo.GetAllTagsForPost(p.Id); } } catch (Exception ex) { _exceptionsRepository.Add(ex); r.Success = false; r.Message = "Failed to load posts."; r.Data = new List <Post>(); } return(r); }
public Response <Blog> GetForIndex() { var r = new Response <Blog>(); var cloud = new Dictionary <Tag, int>(); try { foreach (Tag t in _tagRepository.GetAll()) { cloud.Add(t, _tagsOnPostsRepository.GetTotalCountById(t.Id)); } r.Success = true; r.Message = "Loaded blog data."; r.Data = _blogRepository.Get(); r.Data.TotalNumberOfPosts = _postRepository.GetTotalPostCountByStatus("Approved"); r.Data.StaticPages = _staticPageRepository.GetAll().Where(sp => sp.IsLive == true).ToList(); r.Data.InitialFivePost = _postRepository.GetPostsPaginationByStatus(0, 5, "Approved"); foreach (Post p in r.Data.InitialFivePost) { p.CategoriesOnPost = _categoriesOnPostsRepository.GetAllCategoriesForPost(p.Id); p.TagsOnPost = _tagsOnPostsRepository.GetAllTagsForPost(p.Id); } r.Data.Categories = _categoryRepository.GetAll(); r.Data.TagCloud = cloud; r.Data.StaticPages = new List <StaticPage>(); } catch (Exception ex) { _exceptionsRepository.Add(ex); r.Success = false; r.Message = "Failed to load blog data."; r.Data = new Blog(); } return(r); }