some minor fixes

This commit is contained in:
Zakharov_Rostislav 2024-05-26 22:56:58 +04:00
parent 42c493b475
commit 9e3086f33f
4 changed files with 26 additions and 20 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -377,7 +377,7 @@ namespace BankManagersClientApp.Controllers
}
[HttpPost]
public void WithdrawalUpdate(int withdrawal, int sum, List<int> accounts)
public void WithdrawalUpdate(int withdrawal, List<int> 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");

View File

@ -16,12 +16,6 @@
</select>
</div>
</div>
<div class="row">
<div class="col-4">Сумма:</div>
<div class="col-8">
<input type="number" name="sum" id="sum" />
</div>
</div>
<div class="row">
<div class="col-4">Счета:</div>
<div class="col-8">