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)); }
public ActionResult Index() { var model = new BlogPostsViewModel { TopBlogPosts = Enumerable.Empty <BlogPost>(), BlogPosts = repository.GetBlogPosts() }; return(View("Index", model)); }
public MainForm() { InitializeComponent(); repository = new MemoryBlogPostRepository(); var blogPosts = repository.GetBlogPosts().ToList(); Articles.SetArticles( blogPosts.Select(post => post.Title) ); BlogPostDetailedView.BlogPost = blogPosts.FirstOrDefault(); }
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); }
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]; }
private static IEnumerable <BlogPostViewModel> GetBlogPosts(IBlogPostRepository repository) { return(repository.GetBlogPosts() .Select(blogPost => new BlogPostViewModel(blogPost))); }
public Task <IEnumerable <BlogPost> > GetBlogPosts() { return(blogPostRepository.GetBlogPosts()); }
public JsonResult GetPosts(int currentPostCount = 0) { return(Json(blogPostRepository.GetBlogPosts(currentPostCount))); }
public IActionResult GetBlogPosts() { return(Ok(_blogPostRepository.GetBlogPosts())); }
private static IEnumerable<BlogPostViewModel> GetBlogPosts(IBlogPostRepository repository) { return repository.GetBlogPosts() .Select(blogPost => new BlogPostViewModel(blogPost)); }