Exemplo n.º 1
0
        public async Task <IActionResult> GetBlogPosts()
        {
            var blogPosts = await _repo.GetBlogPosts();

            //var postsToReturn = _mapper.Map<BlogPostsForListDto>(blogPosts);
            var postsToReturn = blogPosts
                                .Select(post => new {
                Id           = post.Id,
                Title        = post.Title,
                Contents     = post.Contents,
                DateCreated  = post.DateCreated,
                DateModified = post.DateModified,
                Excerpt      = post.Excerpt,
                Status       = post.Status,

                Categories = post.BlogPostCategories
                             .Select(cats => new {
                    Id   = cats.Category.Id,
                    Name = cats.Category.Name
                })
            })
                                .ToList();

            return(Ok(postsToReturn));
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            var model = new BlogPostsViewModel
            {
                TopBlogPosts = Enumerable.Empty <BlogPost>(),
                BlogPosts    = repository.GetBlogPosts()
            };

            return(View("Index", model));
        }
Exemplo n.º 3
0
        public MainForm()
        {
            InitializeComponent();

            repository = new MemoryBlogPostRepository();

            var blogPosts = repository.GetBlogPosts().ToList();

            Articles.SetArticles(
                blogPosts.Select(post => post.Title)
                );

            BlogPostDetailedView.BlogPost = blogPosts.FirstOrDefault();
        }
Exemplo n.º 4
0
        public MultipleBlogPostsDTO GetBlogPosts(string tag)
        {
            if (string.IsNullOrEmpty(tag))
            {
                tag = "";
            }
            var blogPosts = _blogPostRepository.GetBlogPosts(tag);
            int count     = blogPosts.Count();

            MultipleBlogPostsDTO multipleBlogPostsDTO = new MultipleBlogPostsDTO();

            multipleBlogPostsDTO.BlogPosts = new List <BlogPostDTO>();

            foreach (var post in blogPosts)
            {
                BlogPostDTO   blogPostDTO = new BlogPostDTO();
                List <string> list        = new List <string>();

                blogPostDTO.Title       = post.Title;
                blogPostDTO.Body        = post.Body;
                blogPostDTO.Description = post.Description;
                blogPostDTO.Slug        = post.Slug;
                blogPostDTO.CreatedAt   = post.CreatedAt;
                blogPostDTO.UpdatedAt   = post.UpdatedAt;

                foreach (var singleTag in post.Tags)
                {
                    list.Add(singleTag.Title);
                }

                string[] tags = list.ToArray();
                blogPostDTO.TagList = tags;

                multipleBlogPostsDTO.BlogPosts.Add(blogPostDTO);
            }
            multipleBlogPostsDTO.PostsCount = count;

            return(multipleBlogPostsDTO);
        }
Exemplo n.º 5
0
        private void Articles_SelectionChanged(object sender, EventArgs e)
        {
            var articles = (sender as ArticlesListBox);

            if (articles == null)
            {
                return;
            }

            var selectedIndex = articles.SelectedIndex;
            var blogPosts     = repository.GetBlogPosts().ToList();

            if (selectedIndex >= blogPosts.Count)
            {
                return;
            }
            if (selectedIndex == -1)
            {
                return;
            }

            BlogPostDetailedView.BlogPost = blogPosts[selectedIndex];
        }
Exemplo n.º 6
0
 private static IEnumerable <BlogPostViewModel> GetBlogPosts(IBlogPostRepository repository)
 {
     return(repository.GetBlogPosts()
            .Select(blogPost => new BlogPostViewModel(blogPost)));
 }
Exemplo n.º 7
0
 public Task <IEnumerable <BlogPost> > GetBlogPosts()
 {
     return(blogPostRepository.GetBlogPosts());
 }
Exemplo n.º 8
0
 public JsonResult GetPosts(int currentPostCount = 0)
 {
     return(Json(blogPostRepository.GetBlogPosts(currentPostCount)));
 }
Exemplo n.º 9
0
 public IActionResult GetBlogPosts()
 {
     return(Ok(_blogPostRepository.GetBlogPosts()));
 }
 private static IEnumerable<BlogPostViewModel> GetBlogPosts(IBlogPostRepository repository)
 {
     return repository.GetBlogPosts()
                      .Select(blogPost => new BlogPostViewModel(blogPost));
 }