Editing products
Editing a product is similar to adding a new product. This time, we need to get the product to edit and prepare the edit form.
Application service contracts
Let's start by defining two new methods for the IProductAppService
interface:
Task<ProductDto> GetAsync(Guid id); Task UpdateAsync(Guid id, CreateUpdateProductDto input);
The first method will be used to obtain the product data by ID. We are reusing CreateUpdateProductDto
(which was defined earlier) in the UpdateAsync
method.
We haven't introduced a new DTO, so we can go straight to the implementation.
Application service implementation
Implementing these new methods is pretty simple. Add the following methods to the ProductAppService
class:
public async Task<ProductDto> GetAsync(Guid id) { return ObjectMapper.Map<Product, ProductDto>( await _productRepository.GetAsync(id) ...