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