Created
December 13, 2019 10:42
-
-
Save mortezadalil/7e46946a543bdb626333a010f14b6030 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.Threading; | |
using System.Threading.Tasks; | |
using Cms.Core.Domain; | |
using Cms.Core.Dtos.UseCaseDtos; | |
using Cms.Core.IRepositories; | |
using MediatR; | |
namespace Cms.Core.Handlers | |
{ | |
public class AddPostHandler : IRequestHandler<AddPostCommand, AddPostResponse> | |
{ | |
private readonly IPostRepository _postRepository; | |
public AddPostHandler(IPostRepository postRepository) | |
{ | |
_postRepository = postRepository; | |
} | |
public async Task<AddPostResponse> Handle(AddPostCommand request, CancellationToken cancellationToken) | |
{ | |
var addedItem = await _postRepository.Add(new Post | |
{ | |
Content = request.Content, | |
Title = request.Title | |
}); | |
return new AddPostResponse | |
{ | |
Content = addedItem.Content, | |
ModifiedDate = addedItem.ModifiedDate, | |
Title = addedItem.Title, | |
CreatedDate = addedItem.CreatedDate, | |
Id = addedItem.Id | |
}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment