From 6980a7e7d697cc3553dd9b4936f764ca73b8a60e Mon Sep 17 00:00:00 2001 From: abazov73 <92822431+abazov73@users.noreply.github.com> Date: Fri, 7 Apr 2023 17:08:15 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B0=20?= =?UTF-8?q?=D1=87=D0=B0=D1=81=D1=82=D1=8C=20View=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D1=80=D0=BE=D0=BB=D0=B8=20=D0=97=D0=B0=D0=BA=D0=B0=D0=B7=D1=87?= =?UTF-8?q?=D0=B8=D0=BA=20+=20=D1=84=D0=B8=D0=BA=D1=81=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D0=BE=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=20Payment=20=D0=B8=20Transfer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SearchModels/OperatorSearchModel.cs | 2 + .../Implements/OperatorStorage.cs | 20 +++- Bank/BankDatabaseImplement/Models/Payment.cs | 4 +- Bank/BankDatabaseImplement/Models/Transfer.cs | 4 +- .../Controllers/OperatorController.cs | 18 +++ .../{APIClientcs.cs => APIClient.cs} | 2 +- .../OperatorApp/Controllers/HomeController.cs | 112 +++++++++++++++++- Bank/OperatorApp/Views/Home/CreateDeal.cshtml | 16 +++ .../Views/Home/CreatePayment.cshtml | 22 ++++ Bank/OperatorApp/Views/Home/Enter.cshtml | 21 ++++ Bank/OperatorApp/Views/Home/Index.cshtml | 63 +++++++++- Bank/OperatorApp/Views/Home/Privacy.cshtml | 40 ++++++- Bank/OperatorApp/Views/Home/Register.cshtml | 33 ++++++ Bank/OperatorApp/Views/Shared/_Layout.cshtml | 30 +++-- 14 files changed, 358 insertions(+), 29 deletions(-) rename Bank/OperatorApp/{APIClientcs.cs => APIClient.cs} (98%) create mode 100644 Bank/OperatorApp/Views/Home/CreateDeal.cshtml create mode 100644 Bank/OperatorApp/Views/Home/CreatePayment.cshtml create mode 100644 Bank/OperatorApp/Views/Home/Enter.cshtml create mode 100644 Bank/OperatorApp/Views/Home/Register.cshtml diff --git a/Bank/BankContracts/SearchModels/OperatorSearchModel.cs b/Bank/BankContracts/SearchModels/OperatorSearchModel.cs index a1e690f..ae59845 100644 --- a/Bank/BankContracts/SearchModels/OperatorSearchModel.cs +++ b/Bank/BankContracts/SearchModels/OperatorSearchModel.cs @@ -10,5 +10,7 @@ namespace BankContracts.SearchModels { public int? Id { get; set; } public string? Login { get; set; } + + public string? Password { get; set; } } } diff --git a/Bank/BankDatabaseImplement/Implements/OperatorStorage.cs b/Bank/BankDatabaseImplement/Implements/OperatorStorage.cs index e8fc543..a9fc467 100644 --- a/Bank/BankDatabaseImplement/Implements/OperatorStorage.cs +++ b/Bank/BankDatabaseImplement/Implements/OperatorStorage.cs @@ -23,15 +23,25 @@ namespace BankDatabaseImplement.Implements } public List 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) { diff --git a/Bank/BankDatabaseImplement/Models/Payment.cs b/Bank/BankDatabaseImplement/Models/Payment.cs index 9dd8482..dfcb260 100644 --- a/Bank/BankDatabaseImplement/Models/Payment.cs +++ b/Bank/BankDatabaseImplement/Models/Payment.cs @@ -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) diff --git a/Bank/BankDatabaseImplement/Models/Transfer.cs b/Bank/BankDatabaseImplement/Models/Transfer.cs index 0643fcf..dd360a5 100644 --- a/Bank/BankDatabaseImplement/Models/Transfer.cs +++ b/Bank/BankDatabaseImplement/Models/Transfer.cs @@ -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) diff --git a/Bank/BankRestApi/Controllers/OperatorController.cs b/Bank/BankRestApi/Controllers/OperatorController.cs index 941fd99..38d5a43 100644 --- a/Bank/BankRestApi/Controllers/OperatorController.cs +++ b/Bank/BankRestApi/Controllers/OperatorController.cs @@ -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) { diff --git a/Bank/OperatorApp/APIClientcs.cs b/Bank/OperatorApp/APIClient.cs similarity index 98% rename from Bank/OperatorApp/APIClientcs.cs rename to Bank/OperatorApp/APIClient.cs index 2e78dac..c289e29 100644 --- a/Bank/OperatorApp/APIClientcs.cs +++ b/Bank/OperatorApp/APIClient.cs @@ -5,7 +5,7 @@ using Newtonsoft.Json; namespace OperatorApp { - public class APIClientcs + public class APIClient { private static readonly HttpClient _client = new(); diff --git a/Bank/OperatorApp/Controllers/HomeController.cs b/Bank/OperatorApp/Controllers/HomeController.cs index 2d16449..9d6500b 100644 --- a/Bank/OperatorApp/Controllers/HomeController.cs +++ b/Bank/OperatorApp/Controllers/HomeController.cs @@ -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>($"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($"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"); + } } } \ No newline at end of file diff --git a/Bank/OperatorApp/Views/Home/CreateDeal.cshtml b/Bank/OperatorApp/Views/Home/CreateDeal.cshtml new file mode 100644 index 0000000..4547f68 --- /dev/null +++ b/Bank/OperatorApp/Views/Home/CreateDeal.cshtml @@ -0,0 +1,16 @@ +@{ + ViewData["Title"] = "CreateDeal"; +} +
+

Создание сделки

+
+
+
+
ID клиента:
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/Bank/OperatorApp/Views/Home/CreatePayment.cshtml b/Bank/OperatorApp/Views/Home/CreatePayment.cshtml new file mode 100644 index 0000000..b4179a9 --- /dev/null +++ b/Bank/OperatorApp/Views/Home/CreatePayment.cshtml @@ -0,0 +1,22 @@ +@{ + ViewData["Title"] = "CreatePayment"; +} +
+

Создание выплаты

+
+
+
+
Изделие:
+
+ +
+
+
+
ID клиента:
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/Bank/OperatorApp/Views/Home/Enter.cshtml b/Bank/OperatorApp/Views/Home/Enter.cshtml new file mode 100644 index 0000000..106d3d5 --- /dev/null +++ b/Bank/OperatorApp/Views/Home/Enter.cshtml @@ -0,0 +1,21 @@ +@{ + ViewData["Title"] = "Enter"; +} + +
+

Вход в приложение

+
+
+
+
Логин:
+
+
+
+
Пароль:
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/Bank/OperatorApp/Views/Home/Index.cshtml b/Bank/OperatorApp/Views/Home/Index.cshtml index d2d19bd..71d534c 100644 --- a/Bank/OperatorApp/Views/Home/Index.cshtml +++ b/Bank/OperatorApp/Views/Home/Index.cshtml @@ -1,8 +1,63 @@ -@{ - ViewData["Title"] = "Home Page"; +@using BankContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Home Page"; }
-

Welcome

-

Learn about building Web apps with ASP.NET Core.

+

Сделки

+ + +
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } + +

+ Создать сделку +

+ + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + } + +
+ Номер сделки + + ID клиента + + ФИО оператора + + Дата +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.ClientId) + + @Html.DisplayFor(modelItem => item.OperatorName) + + @Html.DisplayFor(modelItem => item.DealDate) +
+ } +
\ No newline at end of file diff --git a/Bank/OperatorApp/Views/Home/Privacy.cshtml b/Bank/OperatorApp/Views/Home/Privacy.cshtml index af4fb19..46d074e 100644 --- a/Bank/OperatorApp/Views/Home/Privacy.cshtml +++ b/Bank/OperatorApp/Views/Home/Privacy.cshtml @@ -1,6 +1,36 @@ -@{ - ViewData["Title"] = "Privacy Policy"; -} -

@ViewData["Title"]

+@using BankContracts.ViewModels -

Use this page to detail your site's privacy policy.

+@model OperatorViewModel + +@{ + ViewData["Title"] = "Privacy Policy"; +} +
+

Личные данные

+
+
+
+
Логин:
+
+
+
+
Пароль:
+
+
+
+
Фамилия:
+
+
+
+
Имя:
+
+
+
+
Отчество:
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/Bank/OperatorApp/Views/Home/Register.cshtml b/Bank/OperatorApp/Views/Home/Register.cshtml new file mode 100644 index 0000000..1468e64 --- /dev/null +++ b/Bank/OperatorApp/Views/Home/Register.cshtml @@ -0,0 +1,33 @@ +@{ + ViewData["Title"] = "Register"; +} + +
+

Регистрация

+
+
+
+
Логин:
+
+
+
+
Пароль:
+
+
+
+
Фамилия:
+
+
+
+
Имя:
+
+
+
+
Отчество (необязательно):
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/Bank/OperatorApp/Views/Shared/_Layout.cshtml b/Bank/OperatorApp/Views/Shared/_Layout.cshtml index ff59949..3576b99 100644 --- a/Bank/OperatorApp/Views/Shared/_Layout.cshtml +++ b/Bank/OperatorApp/Views/Shared/_Layout.cshtml @@ -6,24 +6,37 @@ @ViewData["Title"] - OperatorApp - + +