public async Task <bool> DeleteProductAsync(string productId) { await productRepository.DeleteAsync(productId); return(true); /* * bool isProductInAnyOrder = * orderRepository.SelectAll().Any(o => o.LineItems.Any(li => li.Product.Id == productId)); * if (isProductInAnyOrder) * { * //product is in an order: set its discontinued property * Product product = await productRepository.SelectByIdAsync(productId); * product.IsDiscontinued = true; * await productRepository.UpdateAsync(product); * return false; * } * else * { * //product is not in an order: delete it * await productRepository.DeleteAsync(productId); * return true; * } */ }
public async Task <IActionResult> DeleteAsync(string id) { bool deleted = await productRepository.DeleteAsync(id); if (!deleted) { return(NotFound()); } return(new NoContentResult()); }
public async Task <Response <int> > Handle(DeleteProductByIdCommand command, CancellationToken cancellationToken) { var product = await _productRepository.GetByIdAsync(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 <Guid> > Handle(DeleteProductByIdCommand command, CancellationToken cancellationToken) { var product = await _productRepository.GetByIdAsync(command.Id).ConfigureAwait(false); if (product == null) { throw new ApiException($"Product Not Found."); } await _productRepository.DeleteAsync(product).ConfigureAwait(false); await _unitOfWork.Commit <Guid>(cancellationToken).ConfigureAwait(false); return(new Response <Guid>(product.Id)); }
public async Task <Result <int> > Handle(DeleteProductByIdCommand command, CancellationToken cancellationToken) { var product = await _productRepository.GetByIdAsync(command.Id); if (product == null) { return(Result <int> .Failure($"Product with Id {command.Id} does not exist.")); } else { //TODO - Only Admins should be able to delete await _productRepository.DeleteAsync(product); return(Result <int> .Success($"Product with Id {command.Id} deleted.", command.Id)); } }
public async Task <Response <int> > Handle(DeleteProductByIdCommand command, CancellationToken cancellationToken) { var product = await _productRepository.GetByIdAsync(command.Id); if (product == null) { throw new ApiException($"Product Not Found."); } if (command.Physical) { await _productRepository.DeleteAsync(product); } else { product.IsDeleted = true; await _productRepository.UpdateAsync(product); } await _unitOfWork.Commit(cancellationToken); return(new Response <int>(product.Id)); }