-
-
Save tuannguyenssu/d5b874506451c69e7cfe1d8f14f6ab77 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.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