public async Task <int> DeleteAsync(int id) { using (var transaction = DbContext.Database.BeginTransaction()) { try { ProductionOrderModel model = await productionOrderLogic.ReadByIdAsync(id); if (model != null) { ProductionOrderModel productionOrderModel = new ProductionOrderModel(); productionOrderModel = model; await productionOrderLogic.DeleteAsync(id); FinishingPrintingSalesContractModel dataFPSalesContract = await this.finishingPrintingSalesContractLogic.ReadByIdAsync(productionOrderModel.SalesContractId); if (dataFPSalesContract != null) { dataFPSalesContract.RemainingQuantity = dataFPSalesContract.RemainingQuantity + model.OrderQuantity; this.finishingPrintingSalesContractLogic.UpdateAsync(dataFPSalesContract.Id, dataFPSalesContract); } } } catch (Exception e) { transaction.Rollback(); throw new Exception(e.Message); } } return(await DbContext.SaveChangesAsync()); }