public async Task <IActionResult> Delete([FromServices] IPurchaseRepository purchaseRepository, string id) { try { var purchase = await purchaseRepository.GetById(id); if (purchase == null) { _logger.LogInformation($"Pedido com ID: {id} não encontrado."); return(NotFound()); } await purchaseRepository.DeleteAsync(purchase); _logger.LogInformation($"Usuário {User?.Identity.Name} Deletou o pedido com Id: {id}."); return(NoContent()); } catch (Exception ex) { _logger.LogError(ex.Message); return(BadRequest(ex)); } }
public async Task DeleteAsync(int purchaseId) { Purchase purchase = await _purchaseRepository.GetAsync(purchaseId); await _purchaseRepository.DeleteAsync(purchase); }