public async Task <Response <Product> > Handle(GetProductByIdQuery query, CancellationToken cancellationToken) { var product = await _productRepository.Get(query.Id); if (product == null) { throw new ApiException($"Product Not Found."); } return(new Response <Product>(product)); }
public async Task <Response <int> > Handle(DeleteProductByIdCommand command, CancellationToken cancellationToken) { var product = await _productRepository.Get(command.Id); if (product == null) { throw new ApiException($"Product Not Found."); } await _productRepository.DeleteAsync(product); return(new Response <int>(product.Id)); }
public async Task <Response <int> > Handle(UpdateProductCommand command, CancellationToken cancellationToken) { var product = await _productRepository.Get(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 <int>(product.Id)); } }