Compare commits

...

2 Commits

14 changed files with 358 additions and 29 deletions

View File

@ -10,5 +10,7 @@ namespace BankContracts.SearchModels
{
public int? Id { get; set; }
public string? Login { get; set; }
public string? Password { get; set; }
}
}

View File

@ -23,15 +23,25 @@ namespace BankDatabaseImplement.Implements
}
public List<OperatorViewModel> GetFilteredList(OperatorSearchModel model)
{
if (!model.Id.HasValue)
if (!model.Id.HasValue && string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password))
{
return new();
}
using var context = new BankDatabase();
return context.Operators
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
if (!string.IsNullOrEmpty(model.Login) && !string.IsNullOrEmpty(model.Password))
{
return context.Operators
.Where(x => x.Login == model.Login || x.Password == model.Password)
.Select(x => x.GetViewModel)
.ToList();
}
else
{
return context.Operators
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
}
public OperatorViewModel? GetElement(OperatorSearchModel model)
{

View File

@ -62,7 +62,9 @@ namespace BankDatabaseImplement.Models
Deals = model.DealPayments.Select(x => new DealPayment
{
Deal = context.Deals.First(y => y.Id == x.Key)
}).ToList()
}).ToList(),
OperatorId = model.OperatorId,
Operator = context.Operators.First(x => x.Id == model.OperatorId)
};
}
public void Update(PaymentBindingModel? model)

View File

@ -34,7 +34,9 @@ namespace BankDatabaseImplement.Models
Amount = model.Amount,
TransferDateTime = model.TransferDateTime,
PaymentId = model.PaymentId,
Payment = context.Payments.First(x => x.Id == model.PaymentId)
Payment = context.Payments.First(x => x.Id == model.PaymentId),
OperatorId = model.OperatorId,
Operator = context.Operators.First(x => x.Id == model.OperatorId)
};
}
public static Transfer? Create(BankDatabase context, TransferViewModel model)

View File

@ -19,6 +19,24 @@ namespace BankRestApi.Controllers
_operator = operatorC;
}
[HttpGet]
public OperatorViewModel? Login(string login, string password)
{
try
{
return _operator.ReadElement(new OperatorSearchModel
{
Login = login,
Password = password
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка входа в систему");
throw;
}
}
[HttpPost]
public void CreateOperator(OperatorBindingModel model)
{

View File

@ -5,7 +5,7 @@ using Newtonsoft.Json;
namespace OperatorApp
{
public class APIClientcs
public class APIClient
{
private static readonly HttpClient _client = new();

View File

@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using BankContracts.BindingModels;
using BankContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
using OperatorApp.Models;
using System.Diagnostics;
@ -15,12 +17,50 @@ namespace OperatorApp.Controllers
public IActionResult Index()
{
return View();
if (APIClient.Operator == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<DealViewModel>>($"api/deal/getdeals?operatorId={APIClient.Operator.Id}"));
}
[HttpGet]
public IActionResult Privacy()
{
return View();
if (APIClient.Operator == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.Operator);
}
[HttpPost]
public void Privacy(string login, string password, string lastname, string firstname, string middleName)
{
if (APIClient.Operator == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(lastname) || string.IsNullOrEmpty(firstname) || string.IsNullOrEmpty(middleName))
{
throw new Exception("Введите логин, пароль и ФИО");
}
APIClient.PostRequest("api/operator/updateoperator", new OperatorBindingModel
{
Id = APIClient.Operator.Id,
LastName = lastname,
FirstName = firstname,
MiddleName = middleName,
Login = login,
Password = password
});
APIClient.Operator.LastName = lastname;
APIClient.Operator.FirstName = firstname;
APIClient.Operator.MiddleName = middleName;
APIClient.Operator.Login = login;
APIClient.Operator.Password = password;
Response.Redirect("Index");
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
@ -28,5 +68,71 @@ namespace OperatorApp.Controllers
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
[HttpGet]
public IActionResult Enter()
{
return View();
}
[HttpPost]
public void Enter(string login, string password)
{
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
{
throw new Exception("Введите логин и пароль");
}
APIClient.Operator = APIClient.GetRequest<OperatorViewModel>($"api/operator/login?login={login}&password={password}");
if (APIClient.Operator == null)
{
throw new Exception("Неверный логин/пароль");
}
Response.Redirect("Index");
}
[HttpGet]
public IActionResult Register()
{
return View();
}
[HttpPost]
public void Register(string login, string password, string lastname, string firstname, string middleName)
{
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(lastname) || string.IsNullOrEmpty(firstname) || string.IsNullOrEmpty(middleName))
{
throw new Exception("Введите логин, пароль и ФИО");
}
APIClient.PostRequest("api/operator/createOperator", new OperatorBindingModel
{
LastName = lastname,
FirstName = firstname,
MiddleName = middleName,
Login = login,
Password = password
});
Response.Redirect("Enter");
return;
}
[HttpGet]
public IActionResult CreateDeal()
{
return View();
}
[HttpPost]
public void CreateDeal(int clientid)
{
if (APIClient.Operator == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
APIClient.PostRequest("api/main/createorder", new DealBindingModel
{
ClientId = clientid,
OperatorId = APIClient.Operator.Id,
});
Response.Redirect("Index");
}
}
}

View File

@ -0,0 +1,16 @@
@{
ViewData["Title"] = "CreateDeal";
}
<div class="text-center">
<h2 class="display-4">Создание сделки</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">ID клиента:</div>
<div class="col-8"><input type="text" name="clientid" id="clientid" /></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
</div>
</form>

View File

@ -0,0 +1,22 @@
@{
ViewData["Title"] = "CreatePayment";
}
<div class="text-center">
<h2 class="display-4">Создание выплаты</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Изделие:</div>
<div class="col-8">
<select id="product" name="product" class="form-control" asp-items="@(new SelectList(@ViewBag.Pastrys,"Id", "PastryName"))"></select>
</div>
</div>
<div class="row">
<div class="col-4">ID клиента:</div>
<div class="col-8"><input type="text" name="clientid" id="clientid" /></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
</div>
</form>

View File

@ -0,0 +1,21 @@
@{
ViewData["Title"] = "Enter";
}
<div class="text-center">
<h2 class="display-4">Вход в приложение</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Логин:</div>
<div class="col-8"><input type="text" name="login" /></div>
</div>
<div class="row">
<div class="col-4">Пароль:</div>
<div class="col-8"><input type="password" name="password" /></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Вход" class="btn btn-primary" /></div>
</div>
</form>

View File

@ -1,8 +1,63 @@
@{
ViewData["Title"] = "Home Page";
@using BankContracts.ViewModels
@model List<DealViewModel>
@{
ViewData["Title"] = "Home Page";
}
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
<h1 class="display-4">Сделки</h1>
</div>
<div class="text-center">
@{
if (Model == null)
{
<h3 class="display-4">Авторизируйтесь</h3>
return;
}
<p>
<a asp-action="CreateDeal">Создать сделку</a>
</p>
<table class="table">
<thead>
<tr>
<th>
Номер сделки
</th>
<th>
ID клиента
</th>
<th>
ФИО оператора
</th>
<th>
Дата
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.ClientId)
</td>
<td>
@Html.DisplayFor(modelItem => item.OperatorName)
</td>
<td>
@Html.DisplayFor(modelItem => item.DealDate)
</td>
</tr>
}
</tbody>
</table>
}
</div>

View File

@ -1,6 +1,36 @@
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>
@using BankContracts.ViewModels
<p>Use this page to detail your site's privacy policy.</p>
@model OperatorViewModel
@{
ViewData["Title"] = "Privacy Policy";
}
<div class="text-center">
<h2 class="display-4">Личные данные</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Логин:</div>
<div class="col-8"><input type="text" name="login" value="@Model.Login"/></div>
</div>
<div class="row">
<div class="col-4">Пароль:</div>
<div class="col-8"><input type="password" name="password" value="@Model.Password"/></div>
</div>
<div class="row">
<div class="col-4">Фамилия:</div>
<div class="col-8"><input type="text" name="lastname" value="@Model.LastName"/></div>
</div>
<div class="row">
<div class="col-4">Имя:</div>
<div class="col-8"><input type="text" name="firstlename" value="@Model.FirstName"/></div>
</div>
<div class="row">
<div class="col-4">Отчество:</div>
<div class="col-8"><input type="text" name="middlename" value="@Model.MiddleName"/></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
</div>
</form>

View File

@ -0,0 +1,33 @@
@{
ViewData["Title"] = "Register";
}
<div class="text-center">
<h2 class="display-4">Регистрация</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Логин:</div>
<div class="col-8"><input type="text" name="login" /></div>
</div>
<div class="row">
<div class="col-4">Пароль:</div>
<div class="col-8"><input type="password" name="password" /></div>
</div>
<div class="row">
<div class="col-4">Фамилия:</div>
<div class="col-8"><input type="text" name="lastname" /></div>
</div>
<div class="row">
<div class="col-4">Имя:</div>
<div class="col-8"><input type="text" name="firstname" /></div>
</div>
<div class="row">
<div class="col-4">Отчество (необязательно):</div>
<div class="col-8"><input type="text" name="middlename" /></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Регистрация" class="btn btn-primary" /></div>
</div>
</form>

View File

@ -6,24 +6,37 @@
<title>@ViewData["Title"] - OperatorApp</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/OperatorApp.styles.css" asp-append-version="true" />
<link rel="stylesheet" href="~/AbstractShowClientApp.styles.css" asp-append-version="true" />
<script src="~/lib/jquery/dist/jquery.min.js"></script>
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container-fluid">
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">OperatorApp</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Оператор</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Сделки</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Выплаты</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">З</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
</li>
</ul>
</div>
@ -38,12 +51,11 @@
<footer class="border-top footer text-muted">
<div class="container">
&copy; 2023 - OperatorApp - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
&copy; 2023 - ConfectioneryClientApp - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</div>
</footer>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
@await RenderSectionAsync("Scripts", required: false)
</body>
</html>
</html>