From f42809a4e3d79fa3c2435b733e88f89d2fc379ed Mon Sep 17 00:00:00 2001 From: DeepnaPooja Date: Wed, 16 Sep 2026 16:25:50 +0530 Subject: [PATCH] Update return invoice handling --- Distribution/Features/Returns/ReturnService.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Distribution/Features/Returns/ReturnService.cs b/Distribution/Features/Returns/ReturnService.cs index 731bc18..f747542 100644 --- a/Distribution/Features/Returns/ReturnService.cs +++ b/Distribution/Features/Returns/ReturnService.cs @@ -78,7 +78,9 @@ public class ReturnService( if (request.Items is null || request.Items.Count == 0) throw new InvalidOperationException("A return must have at least one line item."); - var sale = await saleRepo.GetByIdAsync(order.FK_SaleId) + if (order.FK_SaleId is null) + throw new InvalidOperationException("Sale not found for this order."); + var sale = await saleRepo.GetByIdAsync(order.FK_SaleId.Value) ?? throw new InvalidOperationException("Sale not found for this order."); if (sale.FK_RideId is null) throw new InvalidOperationException("A return can only be recorded for an order created during an active ride.");