public async Task EditProductAsync(EditProductRequest request, CancellationToken ct) { request.Validate(); if (request.Price == 0) { throw new Exception("O preço do produto não pode ser R$0,00"); } var product = request.ConvertToEntity(); var productregistred = await _productRepository.GetProductByIdAsync(product.ProductId, ct); if (productregistred == null || productregistred.ProductId == Guid.Empty) { throw new Exception("Produto não encotrado para o ID fornecido"); } if (request.File != null) { var urlImage = await ManagerImage.SaveFileAsync(request.File); product.UrlImage = urlImage; ManagerImage.DeleteFile(productregistred.UrlImage); } else { product.UrlImage = productregistred.UrlImage; } await _productRepository.EditProductAsync(product, ct); }
public async Task DeleteProductAsync(Guid productId, CancellationToken ct) { if (productId == Guid.Empty) { throw new ArgumentNullException("Id do produto não fornecido corretamente"); } var product = await _productRepository.GetProductByIdAsync(productId, ct); if (product == null || product.ProductId == Guid.Empty) { throw new Exception("Produto não encotrado para o ID fornecido"); } await _productRepository.DeleteProductAsync(productId, ct); ManagerImage.DeleteFile(product.UrlImage); }