Skip to content

Instantly share code, notes, and snippets.

@mortezadalil
Created December 13, 2019 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mortezadalil/7e8ebcfde9f7a601388527f0c12b4aa2 to your computer and use it in GitHub Desktop.
Save mortezadalil/7e8ebcfde9f7a601388527f0c12b4aa2 to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Cms.Core.Dtos;
using Cms.Core.IRepositories;
using Cms.Core.Queries;
using MediatR;
namespace Cms.Core.Handlers
{
public class GetAllPostHandler : IRequestHandler<GetAllPostQuery, List<PostWithoutCommentsDto>>
{
private readonly IPostRepository _postRepository;
public GetAllPostHandler(IPostRepository postRepository)
{
_postRepository = postRepository;
}
public async Task<List<PostWithoutCommentsDto>> Handle(GetAllPostQuery request, CancellationToken cancellationToken)
{
var posts = await _postRepository.GetAll();
return posts.Select(x => new PostWithoutCommentsDto
{
Content = x.Content,
ModifiedDate = x.ModifiedDate,
CreatedDate = x.CreatedDate,
Title = x.Title,
Id = x.Id
}).ToList();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment