fix Accounts
This commit is contained in:
parent
14cbae5dd6
commit
235fdade5c
@ -56,6 +56,8 @@ namespace BankBusinessLogic.BusinessLogic
|
||||
public bool Create(AccountBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
model.Money = 0;
|
||||
model.ReleaseDate = DateTime.Now;
|
||||
if (_accountStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
|
@ -18,7 +18,7 @@ namespace BankDatabaseImplement.Implements
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
return context.Accounts
|
||||
.Include(x => x.ManagerId)
|
||||
.Include(x => x.Manager)
|
||||
.Include(x => x.AccountWithdrawals)
|
||||
.Include(x => x.SenderTransfers)
|
||||
.Include(x => x.RecipientTransfers)
|
||||
@ -29,7 +29,7 @@ namespace BankDatabaseImplement.Implements
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
return context.Accounts
|
||||
.Include(x => x.ManagerId)
|
||||
.Include(x => x.Manager)
|
||||
.Include(x => x.AccountWithdrawals)
|
||||
.Include(x => x.SenderTransfers)
|
||||
.Include(x => x.RecipientTransfers)
|
||||
@ -46,7 +46,7 @@ namespace BankDatabaseImplement.Implements
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
return context.Accounts
|
||||
.Include(x => x.ManagerId)
|
||||
.Include(x => x.Manager)
|
||||
.Include(x => x.AccountWithdrawals)
|
||||
.Include(x => x.SenderTransfers)
|
||||
.Include(x => x.RecipientTransfers)
|
||||
@ -73,7 +73,7 @@ namespace BankDatabaseImplement.Implements
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
var account = context.Accounts
|
||||
.Include(x => x.ManagerId)
|
||||
.Include(x => x.Manager)
|
||||
.Include(x => x.AccountWithdrawals)
|
||||
.Include(x => x.SenderTransfers)
|
||||
.Include(x => x.RecipientTransfers)
|
||||
@ -91,7 +91,7 @@ namespace BankDatabaseImplement.Implements
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
var account = context.Accounts
|
||||
.Include(x => x.ManagerId)
|
||||
.Include(x => x.Manager)
|
||||
.Include(x => x.AccountWithdrawals)
|
||||
.Include(x => x.SenderTransfers).Include(x => x.RecipientTransfers)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
@ -1,4 +1,5 @@
|
||||
using BankContracts.ViewModels;
|
||||
using BankContracts.BindingModels;
|
||||
using BankContracts.ViewModels;
|
||||
using BankManagersClientApp.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
@ -14,7 +15,7 @@ namespace BankManagersClientApp.Controllers
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
#region//ManagerAccounts
|
||||
#region//Managers
|
||||
[HttpGet]
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
@ -29,7 +30,7 @@ namespace BankManagersClientApp.Controllers
|
||||
public void Enter(string login, string password)
|
||||
{
|
||||
if (string.IsNullOrEmpty(login) ||
|
||||
string.IsNullOrEmpty(password))
|
||||
string.IsNullOrEmpty(password))
|
||||
{
|
||||
throw new Exception("Введите логин и пароль");
|
||||
}
|
||||
@ -48,8 +49,19 @@ namespace BankManagersClientApp.Controllers
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region//работа со счетами
|
||||
#region//Accounts
|
||||
[HttpGet]
|
||||
public IActionResult Index()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIClient.GetRequest<List<AccountViewModel>>($"api/account/getaccountlist?managerid={APIClient.Client.Id}"));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult AccountCreate()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
@ -58,36 +70,95 @@ namespace BankManagersClientApp.Controllers
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult AccountCreate()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public void AccountCreate(string number)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
APIClient.PostRequest("api/account/createaccount", new
|
||||
AccountBindingModel
|
||||
{
|
||||
ManagerId = APIClient.Client.Id,
|
||||
Number = number
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult AccountUpdate()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Accounts = APIClient.GetRequest<List<AccountViewModel>>($"api/account/getaccountlist?managerid={APIClient.Client.Id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void AccountUpdate(int account, string number, int money)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
APIClient.PostRequest("api/account/updateaccount", new
|
||||
AccountBindingModel
|
||||
{
|
||||
Id = account,
|
||||
ManagerId = APIClient.Client.Id,
|
||||
Number = number,
|
||||
Money = money
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public AccountViewModel? GetAccount(int accountId)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
var result = APIClient.GetRequest<AccountViewModel>($"api/account/getaccount?accountid={accountId}");
|
||||
if (result == null)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult AccountDelete()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Accounts = APIClient.GetRequest<List<AccountViewModel>>($"api/account/getaccountlist?managerid={APIClient.Client.Id}");
|
||||
return View();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region//работа с переводами
|
||||
public IActionResult Transfers()
|
||||
[HttpPost]
|
||||
public void AccountDelete(int account)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
APIClient.PostRequest("api/account/deleteaccount", new
|
||||
AccountBindingModel
|
||||
{
|
||||
Id = account,
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region//работа с переводами
|
||||
public IActionResult Transfers()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
|
@ -7,14 +7,18 @@
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Карта:</div>
|
||||
<div class="col-4">Счёт:</div>
|
||||
<div class="col-8">
|
||||
<select id="account" name="account" class="form-control" asp-items="@(new SelectList(@ViewBag.Accounts, "Id", "Number"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Номер:</div>
|
||||
<div class="col-8"><input type="text" name="number" id="number" class="form-control" /></div>
|
||||
<div class="col-8"><input type="text" name="number" id="number" class="form-control" readonly /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Деньги:</div>
|
||||
<div class="col-8"><input type="number" name="money" id="money" class="form-control" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
@ -33,7 +37,8 @@
|
||||
url: "/Home/GetAccount",
|
||||
data: { accountId: account },
|
||||
success: function (result) {
|
||||
$('#number').val(result.item1.number);
|
||||
$('#number').val(result.number);
|
||||
$('#money').val(result.money);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@ -8,11 +8,6 @@
|
||||
</div>
|
||||
<div class="text-center">
|
||||
@{
|
||||
if (Model == null)
|
||||
{
|
||||
<h3 class="display-4">Авторизируйтесь</h3>
|
||||
return;
|
||||
}
|
||||
<p>
|
||||
<a asp-action="AccountCreate">Создать счет</a>
|
||||
<a asp-action="AccountUpdate">Обновить счет</a>
|
||||
@ -24,7 +19,6 @@
|
||||
<th>Номер</th>
|
||||
<th>Деньги на счёте</th>
|
||||
<th>Дата открытия</th>
|
||||
<th>Менеджер</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -43,10 +37,6 @@
|
||||
@Html.DisplayFor(modelItem =>
|
||||
item.ReleaseDate)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem =>
|
||||
item.ManagerName)
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
|
Loading…
Reference in New Issue
Block a user