public async Task <Response <Product> > Handle(GetProductByIdQuery query, CancellationToken cancellationToken) { var product = await _productRepository.GetSingleByCondition(x => x.Id == query.Id, null, x => new Product() { Id = x.Id, Name = x.Name }); if (product == null) { throw new ApiException($"Product Not Found."); } return(new Response <Product>(product)); }
public async Task <Response <long> > Handle(UpdateProductCommand command, CancellationToken cancellationToken) { var product = await _productRepository.GetSingleByCondition(x => x.Id == command.Id); if (product == null) { throw new ApiException($"Product Not Found."); } else { product.Name = command.Name; product.Rate = command.Rate; product.Description = command.Description; await _productRepository.UpdateAsync(product); return(new Response <long>(product.Id)); } }