Exemple #1
0
 public RssResult(PostListViewModel model)
     : base("application/rss+xml")
 {
     _view = model;
     if (_view == null) return;
     _httpHelper = ObjectFactory.GetInstance<IHttpHelper>();
     _feed = new SyndicationFeed(_view.BlogTitle, _view.SubHead, HttpContext.Current.Request.Url, BuildItems());
 }
Exemple #2
0
        public PostListViewModel GetAllPostForBlog()
        {
            Blog blog = GetCurrentBlog();
            var view = new PostListViewModel();
            if (blog == null) return view;

            view.BlogId = blog.Id;
            view.BlogTitle = blog.BlogName;
            List<Post> posts = _postRepository.GetAllPosts().ToList();
            view.Posts = new List<PostViewModel>();
            foreach (Post post in posts)
            {
                PostViewModel item = _postMappingService.MapToView(post);
                view.Posts.Add(item);
            }
            return view;
        }
Exemple #3
0
        public PostListViewModel GetPostBySlug(string slug)
        {
            Post post =
                _postRepository.GetAllPosts().FirstOrDefault(
                    x => x.Slug == slug && x.Blog.IsActive && x.Blog.IsPrimary && !x.IsDeleted && x.IsPublished);
            if (post == null) return new PostListViewModel { ErrorMessage = "The specified post was not found." };

            var list = new PostListViewModel
                {
                    BlogId = post.Blog.Id,
                    BlogTitle = post.Blog.BlogName,
                    SubHead = post.Blog.SubHead,
                    Posts = new List<PostViewModel>()
                };
            PostViewModel item = _postMappingService.MapToView(post);
            item.Tags = MapTags(post);
            item.UserFullName = string.Format("{0} {1}", post.User.FirstName, post.User.LastName);
            list.Posts.Add(item);
            return list;
        }
Exemple #4
0
        public PostListViewModel GetTopMostRecentPosts(int top)
        {
            if (top == 0) top = 5;
            List<Post> posts = _postRepository.GetAllPosts()
                .Where(x => x.IsPublished && !x.IsDeleted && x.Blog.IsActive && x.Blog.IsPrimary)
                .Take(top)
                .OrderByDescending(x => x.DatePublished)
                .ToList();
            var viewModel = new PostListViewModel { Posts = new List<PostViewModel>() };
            if (posts.Count == 0)
            {
                viewModel.ErrorMessage = "No posts were found.";
                return viewModel;
            }
            Blog blog = posts.First().Blog;
            viewModel.BlogId = blog.Id;
            viewModel.BlogTitle = blog.BlogName;
            viewModel.SubHead = blog.SubHead;

            foreach (Post post in posts)
            {
                PostViewModel item = _postMappingService.MapToView(post);
                viewModel.Posts.Add(item);
            }

            return viewModel;
        }
Exemple #5
0
        public PostListViewModel GetAllPostsForTag(string urlEncodedTag)
        {
            string tag = urlEncodedTag.Replace('+', ' ');
            List<Post> posts = _postRepository.GetAllPosts().Where(x => x.Tags.Any(y => y.TagName == tag))
                .Where(x => x.Blog.IsActive && x.Blog.IsPrimary && !x.IsDeleted && x.IsPublished)
                .OrderByDescending(x => x.DatePublished)
                .ToList();

            var list = new PostListViewModel { Posts = new List<PostViewModel>() };
            if (posts.Count == 0)
            {
                list.ErrorMessage = "The selected posts were not found.";
                return list;
            }

            Blog blog = posts.First().Blog;
            UserProfile user = posts.First().User;
            list.BlogId = blog.Id;
            list.BlogTitle = blog.BlogName;
            list.SubHead = blog.SubHead;
            list.UserFullName = user.FirstName + " " + user.LastName;
            foreach (Post post in posts)
            {
                PostViewModel item = _postMappingService.MapToView(post);
                item.Tags = MapTags(post);
                list.Posts.Add(item);
            }
            list.Tag = tag;
            return list;
        }