Created
December 13, 2019 10:39
-
-
Save mortezadalil/7e8ebcfde9f7a601388527f0c12b4aa2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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