Skip to content

Instantly share code, notes, and snippets.

@tuannguyenssu
Created August 15, 2019 15:29
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 tuannguyenssu/d5b874506451c69e7cfe1d8f14f6ab77 to your computer and use it in GitHub Desktop.
Save tuannguyenssu/d5b874506451c69e7cfe1d8f14f6ab77 to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using CQRSTest.Application.Exceptions;
using CQRSTest.Domain;
using MediatR;
namespace CQRSTest.Application.Customers.Queries.GetCustomerDetail
{
public class GetCustomerDetailQueryHandler : IRequestHandler<GetCustomerDetailQuery, CustomerDetailViewModel>
{
public async Task<CustomerDetailViewModel> Handle(GetCustomerDetailQuery request, CancellationToken cancellationToken)
{
// Ở đây chỉ giả lập dữ liệu. Trên thực tế phải tương tác với DB thật
var model = FakeDbContext.Customers.Find(c => c.Id == request.Id);
if(model == null)
{
throw new NotFoundException(nameof(Customer), request.Id);
}
var vm = new CustomerDetailViewModel
{
Name = model.Name,
Address = model.Address
};
return await Task.FromResult(vm);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment