diff --git a/Bank/BankDatabaseImplement/Implements/TransferStorage.cs b/Bank/BankDatabaseImplement/Implements/TransferStorage.cs index d75250f..e3e52cf 100644 --- a/Bank/BankDatabaseImplement/Implements/TransferStorage.cs +++ b/Bank/BankDatabaseImplement/Implements/TransferStorage.cs @@ -66,13 +66,13 @@ namespace BankDatabaseImplement.Implements { MakeTransfer(context, model); context.Transfers.Add(newTransfer); + context.SaveChanges(); } catch { transaction.Rollback(); throw; } - context.SaveChanges(); transaction.Commit(); return newTransfer.GetViewModel; } @@ -94,13 +94,13 @@ namespace BankDatabaseImplement.Implements }); MakeTransfer(context, model); oldTransfer.Update(model); + context.SaveChanges(); } catch { transaction.Rollback(); throw; } - context.SaveChanges(); transaction.Commit(); return oldTransfer.GetViewModel; } @@ -121,13 +121,13 @@ namespace BankDatabaseImplement.Implements Sum = oldTransfer.Sum, }); context.Transfers.Remove(oldTransfer); + context.SaveChanges(); } catch { transaction.Rollback(); throw; } - context.SaveChanges(); transaction.Commit(); return oldTransfer.GetViewModel; } diff --git a/Bank/BankDatabaseImplement/Implements/WithdrawalStorage.cs b/Bank/BankDatabaseImplement/Implements/WithdrawalStorage.cs index 3142032..fc39deb 100644 --- a/Bank/BankDatabaseImplement/Implements/WithdrawalStorage.cs +++ b/Bank/BankDatabaseImplement/Implements/WithdrawalStorage.cs @@ -81,13 +81,13 @@ namespace BankDatabaseImplement.Implements if (newWithdrawal == null) throw new InvalidOperationException("Error during creating new withdrawal"); context.Withdrawals.Add(newWithdrawal); + context.SaveChanges(); } catch { transaction.Rollback(); throw; } - context.SaveChanges(); transaction.Commit(); return newWithdrawal.GetViewModel; } @@ -102,16 +102,17 @@ namespace BankDatabaseImplement.Implements withdrawal = context.Withdrawals.FirstOrDefault(x => x.Id == model.Id); if (withdrawal == null) throw new InvalidOperationException("Updating withdrawal was not found"); + if (withdrawal.RequestId != null) + throw new InvalidOperationException("Update was rejected: withdrawal was done"); withdrawal.Update(model); - MakeWithdrawal(context, model); withdrawal.UpdateAccounts(context, model); + context.SaveChanges(); } catch { transaction.Rollback(); throw; } - context.SaveChanges(); transaction.Commit(); return withdrawal.GetViewModel; } @@ -119,13 +120,24 @@ namespace BankDatabaseImplement.Implements public WithdrawalViewModel? LinkToRequest(int withdrawalId, int requestId) { if (requestId <= 0 || withdrawalId <= 0) - return null; + throw new InvalidOperationException("Id must be positive number"); using var context = new BankDatabase(); - var withdrawal = context.Withdrawals.FirstOrDefault(x => x.Id == withdrawalId); - if (withdrawal == null) - return null; - withdrawal.LinkToRequest(requestId); - context.SaveChanges(); + using var transaction = context.Database.BeginTransaction(); + Withdrawal? withdrawal; + try + { + withdrawal = context.Withdrawals.FirstOrDefault(x => x.Id == withdrawalId); + if (withdrawal == null) + throw new InvalidOperationException("Withdrawal was not found"); + withdrawal.LinkToRequest(requestId); + context.SaveChanges(); + } + catch + { + transaction.Rollback(); + throw; + } + transaction.Commit(); return withdrawal.GetViewModel; } diff --git a/Bank/BankManagersClientApp/Controllers/HomeController.cs b/Bank/BankManagersClientApp/Controllers/HomeController.cs index 21779bb..9e627f3 100644 --- a/Bank/BankManagersClientApp/Controllers/HomeController.cs +++ b/Bank/BankManagersClientApp/Controllers/HomeController.cs @@ -377,7 +377,7 @@ namespace BankManagersClientApp.Controllers } [HttpPost] - public void WithdrawalUpdate(int withdrawal, int sum, List accounts) + public void WithdrawalUpdate(int withdrawal, List accounts) { if (APIClient.Client == null) throw new Exception("Вы как суда попали? Суда вход только авторизованным"); @@ -392,7 +392,7 @@ namespace BankManagersClientApp.Controllers APIClient.PostRequest("/api/withdrawal/updatewithdrawal", new WithdrawalBindingModel { Id = withdrawal, - Sum = sum, + Sum = 0, WithdrawalAccounts = dictionary, }); Response.Redirect("Withdrawals"); diff --git a/Bank/BankManagersClientApp/Views/Home/WithdrawalUpdate.cshtml b/Bank/BankManagersClientApp/Views/Home/WithdrawalUpdate.cshtml index a98a67e..1b11b08 100644 --- a/Bank/BankManagersClientApp/Views/Home/WithdrawalUpdate.cshtml +++ b/Bank/BankManagersClientApp/Views/Home/WithdrawalUpdate.cshtml @@ -16,12 +16,6 @@ -
-
Сумма:
-
- -
-
Счета:
diff --git a/Bank/BankManagersClientApp/Views/Shared/_Layout.cshtml b/Bank/BankManagersClientApp/Views/Shared/_Layout.cshtml index efc043c..ce6d34a 100644 --- a/Bank/BankManagersClientApp/Views/Shared/_Layout.cshtml +++ b/Bank/BankManagersClientApp/Views/Shared/_Layout.cshtml @@ -60,7 +60,7 @@