public async Task <IHttpActionResult> Delete(Guid percentDiscountId, Guid productId) { var command = new DeleteProductFromPercentDiscountCommand { PercentDiscount = percentDiscountId, ProductId = productId }; var response = await Bus.Send <DeleteProductFromPercentDiscountCommand, DeleteProductFromPercentDiscountCommandResponse>( command); return(Ok(response)); }
public async Task <DeleteProductFromPercentDiscountCommandResponse> Handle(DeleteProductFromPercentDiscountCommand command) { var discount = await _percentRepository.AsQuery().SingleOrDefaultAsync(p => p.Id == command.PercentDiscount); if (discount == null) { throw new DomainException("تخفیف یافت نشد"); } var productDiscount = discount.ProductDiscounts.SingleOrDefault(p => p.Product.Id == command.ProductId); if (productDiscount == null) { throw new DomainException("محصولی یافت نشد"); } discount.ProductDiscounts.Remove(productDiscount); var product = await _productRepository.FindAsync(command.ProductId); product.ProductDiscount = null; return(new DeleteProductFromPercentDiscountCommandResponse()); }