Merge branch 'ManagersApp' of https://git.is.ulstu.ru/Artyom_Yashin/PIbd-23_Yashin_A_Zakharov_R_CourseWork_Bank into ManagersApp
This commit is contained in:
commit
504469416d
@ -3,6 +3,7 @@ using BankContracts.SearchModels;
|
||||
using BankContracts.StoragesContracts;
|
||||
using BankContracts.ViewModels;
|
||||
using BankDatabaseImplement.Models;
|
||||
using BankDataModels.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -57,14 +58,61 @@ namespace BankDatabaseImplement.Implements
|
||||
public WithdrawalViewModel? Insert(WithdrawalBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
var newWithdrawal = Withdrawal.Create(context, model);
|
||||
if (newWithdrawal == null)
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
Withdrawal? newWithdrawal;
|
||||
try
|
||||
{
|
||||
return null;
|
||||
newWithdrawal = Withdrawal.Create(context, model);
|
||||
if (newWithdrawal == null)
|
||||
throw new InvalidOperationException("Error during creating new withdrawal");
|
||||
context.Withdrawals.Add(newWithdrawal);
|
||||
}
|
||||
context.Withdrawals.Add(newWithdrawal);
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
context.SaveChanges();
|
||||
return newWithdrawal.GetViewModel;
|
||||
transaction.Commit();
|
||||
return newWithdrawal.GetViewModel;
|
||||
}
|
||||
|
||||
private void MakeWithdrawal(BankDatabase context, WithdrawalBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
int count = model.Sum;
|
||||
if (count == 0)
|
||||
return;
|
||||
var dictionary = model.WithdrawalAccounts;
|
||||
var keys = dictionary.Keys;
|
||||
foreach (int key in keys)
|
||||
{
|
||||
(IAccountModel, int) value = new();
|
||||
bool result = dictionary.TryGetValue(key, out value);
|
||||
if (!result)
|
||||
throw new InvalidOperationException("Value was not got");
|
||||
Account account = context.Accounts.FirstOrDefault(x => x.Id == key) ??
|
||||
throw new InvalidOperationException("Needed account was not found");
|
||||
int dif = count;
|
||||
if (account.Money < dif)
|
||||
dif = account.Money;
|
||||
value.Item2 = dif;
|
||||
dictionary[key] = value;
|
||||
count -= dif;
|
||||
account.Update(new AccountBindingModel
|
||||
{
|
||||
Id = account.Id,
|
||||
Number = account.Number,
|
||||
ReleaseDate = account.ReleaseDate,
|
||||
ManagerId = account.ManagerId,
|
||||
Money = account.Money - dif,
|
||||
});
|
||||
if (count == 0)
|
||||
break;
|
||||
}
|
||||
if (count > 0)
|
||||
throw new InvalidOperationException("The accounts did not have enough money");
|
||||
}
|
||||
|
||||
public WithdrawalViewModel? Update(WithdrawalBindingModel model)
|
||||
|
@ -226,8 +226,9 @@ namespace BankManagersClientApp.Controllers
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Accounts = APIClient.GetRequest<List<AccountViewModel>>($"api/account/getaccountlist?managerid={APIClient.Client.Id}");
|
||||
return View();
|
||||
ViewBag.SenderAccounts = APIClient.GetRequest<List<AccountViewModel>>($"api/account/getaccountlist?managerid={APIClient.Client.Id}");
|
||||
ViewBag.RecipientAccounts = APIClient.GetRequest<List<AccountViewModel>>("api/account/getaccountlist");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@ -256,8 +257,9 @@ namespace BankManagersClientApp.Controllers
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Transfers = APIClient.GetRequest<List<TransferViewModel>>($"api/transfer/gettransferlist?managerid={APIClient.Client.Id}");
|
||||
ViewBag.Accounts = APIClient.GetRequest<List<AccountViewModel>>($"api/account/getaccountlist?managerid={APIClient.Client.Id}");
|
||||
return View();
|
||||
ViewBag.SenderAccounts = APIClient.GetRequest<List<AccountViewModel>>($"api/account/getaccountlist?managerid={APIClient.Client.Id}");
|
||||
ViewBag.RecipientAccounts = APIClient.GetRequest<List<AccountViewModel>>("api/account/getaccountlist");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
|
@ -15,14 +15,14 @@
|
||||
<div class="col-4">Номер счета отправителя:</div>
|
||||
<div class="col-8">
|
||||
<select name="senderaccount" id="senderaccount" class="form-control"
|
||||
asp-items="@(new SelectList(@ViewBag.Accounts, "Id", "Number"))"></select>
|
||||
asp-items="@(new SelectList(@ViewBag.SenderAccounts, "Id", "Number"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Номер счета получателя:</div>
|
||||
<div class="col-8">
|
||||
<select name="recipientaccount" id="recipientaccount" class="form-control"
|
||||
asp-items="@(new SelectList(@ViewBag.Accounts, "Id", "Number"))"></select>
|
||||
asp-items="@(new SelectList(@ViewBag.RecipientAccounts, "Id", "Number"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
|
@ -25,13 +25,13 @@
|
||||
<div class="row">
|
||||
<div class="col-4">Отправитель:</div>
|
||||
<div class="col-8">
|
||||
<select id="senderaccount" name="senderaccount" class="form-control" asp-items="@(new SelectList(@ViewBag.Accounts, "Id", "Number"))"></select>
|
||||
<select id="senderaccount" name="senderaccount" class="form-control" asp-items="@(new SelectList(@ViewBag.SenderAccounts, "Id", "Number"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Получатель:</div>
|
||||
<div class="col-8">
|
||||
<select id="recipientaccount" name="recipientaccount" class="form-control" asp-items="@(new SelectList(@ViewBag.Accounts, "Id", "Number"))"></select>
|
||||
<select id="recipientaccount" name="recipientaccount" class="form-control" asp-items="@(new SelectList(@ViewBag.RecipientAccounts, "Id", "Number"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
|
@ -21,7 +21,7 @@ namespace BankRestApi.Controllers
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<AccountViewModel>? GetAccountList(int managerId)
|
||||
public List<AccountViewModel>? GetAccountList(int? managerId)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user