public bool CancelSale(int saleId) { var sale = _salesRepo.GetSale(saleId); if (sale == null) { return(false); } else { // _salesRepo.DeleteSaleInvoice(saleId); if (sale.Finalised == true) { var saleItems = _salesRepo.GetProductSalesInTransaction(saleId); if (sale.Canceled == false) { foreach (ProductSale item in saleItems) { _inventoryRepo.IncreaseProductQty(item.Id, 1); } } } sale.Canceled = true; // _salesRepo.ClearProductSales(saleId); _salesRepo.CancelSale(sale); // _salesRepo.DeleteSalePayments(saleId); return(true); } }