Skip to content

Instantly share code, notes, and snippets.

@mortezadalil
Created December 13, 2019 10:42
Show Gist options
  • Save mortezadalil/7e46946a543bdb626333a010f14b6030 to your computer and use it in GitHub Desktop.
Save mortezadalil/7e46946a543bdb626333a010f14b6030 to your computer and use it in GitHub Desktop.
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