From fceffcf0b6f1fcc67c32b78914a93e2c0f5bc605 Mon Sep 17 00:00:00 2001 From: ksenianeva <95441235+ksenianeva@users.noreply.github.com> Date: Fri, 19 May 2023 21:52:31 +0400 Subject: [PATCH] =?UTF-8?q?Homecontroller=20=D0=B1=D0=B5=D0=B7=20=D0=BE?= =?UTF-8?q?=D1=82=D1=87=D0=B5=D1=82=D0=BE=D0=B2=20=D1=83=20=D0=BE=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=B0=20=D0=B1=D0=B0=D0=BD?= =?UTF-8?q?=D0=BA=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bank/BankOperatorApp/APIClient.cs | 2 +- .../Controllers/HomeController.cs | 145 +++++++++++++----- 2 files changed, 108 insertions(+), 39 deletions(-) diff --git a/Bank/BankOperatorApp/APIClient.cs b/Bank/BankOperatorApp/APIClient.cs index 4df62ce..ed05568 100644 --- a/Bank/BankOperatorApp/APIClient.cs +++ b/Bank/BankOperatorApp/APIClient.cs @@ -9,7 +9,7 @@ namespace BankOperatorApp { private static readonly HttpClient _client = new(); - public static OperatorViewModel? Operator { get; set; } = null; + public static BankOperatorViewModel? BankOperator { get; set; } = null; public static void Connect(IConfiguration configuration) { diff --git a/Bank/BankOperatorApp/Controllers/HomeController.cs b/Bank/BankOperatorApp/Controllers/HomeController.cs index 704d5eb..f1bbd49 100644 --- a/Bank/BankOperatorApp/Controllers/HomeController.cs +++ b/Bank/BankOperatorApp/Controllers/HomeController.cs @@ -3,51 +3,67 @@ using BankContracts.ViewModels; using Microsoft.AspNetCore.Mvc; using BankOperatorApp.Models; using System.Diagnostics; +using BankContracts.BusinessLogicsContracts; +using BankContracts.SearchModels; +using BankDataModels.Models; namespace BankOperatorApp.Controllers { public class HomeController : Controller { private readonly ILogger _logger; + private readonly IBankOperatorLogic _bankOperatorLogic; + private readonly ICreditProgramLogic _creditProgramLogic; + private readonly ICurrencyLogic _currencyLogic; + private ICurrencyPurchaseLogic _currencyPurchaseLogic; - public HomeController(ILogger logger) + public HomeController(ILogger logger, IBankOperatorLogic bankOperatorLogic, + ICreditProgramLogic creditProgramLogic, ICurrencyLogic currencyLogic, + ICurrencyPurchaseLogic currencyPurchaseLogic) { _logger = logger; + _bankOperatorLogic = bankOperatorLogic; + _creditProgramLogic = creditProgramLogic; + _currencyLogic = currencyLogic; + _currencyPurchaseLogic = currencyPurchaseLogic; } public IActionResult Index() { - if (APIClient.Operator == null) + if (APIClient.BankOperator == null) { return Redirect("~/Home/Enter"); } - return View(APIClient.GetRequest>($"api/deal/getdeals?operatorId={APIClient.Operator.Id}")); + return View(_currencyLogic.ReadList(new CurrencySearchModel { BankOperatorId = + APIClient.BankOperator.Id })); } [HttpGet] public IActionResult Privacy() { - if (APIClient.Operator == null) + if (APIClient.BankOperator == null) { return Redirect("~/Home/Enter"); } - return View(APIClient.Operator); + return View(APIClient.BankOperator); } [HttpPost] - public void Privacy(string login, string password, string lastname, string firstname, string middleName) + public void Privacy(string login, string password, string lastname, + string firstname, string middleName) { - if (APIClient.Operator == null) + if (APIClient.BankOperator == null) { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } - if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(lastname) || string.IsNullOrEmpty(firstname) || string.IsNullOrEmpty(middleName)) + 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 + APIClient.PostRequest("api/bankoperator/updatebankoperator", new OperatorBindingModel { - Id = APIClient.Operator.Id, + Id = APIClient.BankOperator.Id, LastName = lastname, FirstName = firstname, MiddleName = middleName, @@ -55,18 +71,19 @@ namespace BankOperatorApp.Controllers Password = password }); - APIClient.Operator.LastName = lastname; - APIClient.Operator.FirstName = firstname; - APIClient.Operator.MiddleName = middleName; - APIClient.Operator.Login = login; - APIClient.Operator.Password = password; + APIClient.BankOperator.LastName = lastname; + APIClient.BankOperator.FirstName = firstname; + APIClient.BankOperator.MiddleName = middleName; + APIClient.BankOperator.Login = login; + APIClient.BankOperator.Password = password; Response.Redirect("Index"); } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { - return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + return View(new ErrorViewModel { RequestId = + Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } [HttpGet] @@ -82,8 +99,10 @@ namespace BankOperatorApp.Controllers { throw new Exception("Введите логин и пароль"); } - APIClient.Operator = APIClient.GetRequest($"api/operator/login?login={login}&password={password}"); - if (APIClient.Operator == null) + APIClient.BankOperator = APIClient. + GetRequest + ($"api/bankoperator/login?login={login}&password={password}"); + if (APIClient.BankOperator == null) { throw new Exception("Неверный логин/пароль"); } @@ -97,13 +116,16 @@ namespace BankOperatorApp.Controllers } [HttpPost] - public void Register(string login, string password, string lastname, string firstname, string middleName) + 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)) + 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 + APIClient.PostRequest("api/bankoperator/createbankoperator", new BankOperatorBindingModel { LastName = lastname, FirstName = firstname, @@ -115,52 +137,99 @@ namespace BankOperatorApp.Controllers return; } [HttpGet] - public IActionResult CreateDeal() + public IActionResult CreateCurrency() { return View(); } [HttpPost] - public void CreateDeal(int clientid) + public void CreateCurrency(string name) { - if (APIClient.Operator == null) + if (APIClient.BankOperator == null) { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } - APIClient.PostRequest("api/deal/createdeal", new DealBindingModel + APIClient.PostRequest("api/currency/createcurrency", new CurrencyBindingModel { - ClientId = clientid, - OperatorId = APIClient.Operator.Id, + BankOperatorId = APIClient.BankOperator.Id, + Name = name, }); Response.Redirect("Index"); } - public IActionResult Payments() + public IActionResult CreditPrograms() { - if (APIClient.Operator == null) + if (APIClient.BankOperator == null) { return Redirect("~/Home/Enter"); } - return View(APIClient.GetRequest>($"api/payment/getpayments?operatorId={APIClient.Operator.Id}")); + return View(APIClient.GetRequest + > + ($"api/creditprogram/getcreditprograms?bankoperatorId={APIClient.BankOperator.Id}")); } [HttpGet] - public IActionResult CreatePayment() + public IActionResult CreateCreditProgram() { - ViewBag.Deals = APIClient.GetRequest>("api/deal/getdealslist"); + ViewBag.Currencies = APIClient.GetRequest> + ("api/currency/getcurrencieslist"); return View(); } [HttpPost] - public void CreatePayment(int clientid) + public void CreateCreditProgram(List currenciess) { - if (APIClient.Operator == null) + if (APIClient.BankOperator == null) { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } - APIClient.PostRequest("api/deal/createdeal", new PaymentBindingModel + Dictionary CurrencyCreditPrograms = new(); + foreach (int id in currenciess) { + var currency = _currencyLogic.ReadElement(new CurrencySearchModel { Id = id }); + if (currency != null) CurrencyCreditPrograms.Add(currency.Id, currency); + } + _creditProgramLogic.Create(new CreditProgramBindingModel { BankOperatorId = + APIClient.BankOperator.Id, + CreditProgramCurrencies = CurrencyCreditPrograms, }); + Response.Redirect("Payments"); + } + [HttpGet] + public IActionResult CreditProgram(int id) + { + return View(_creditProgramLogic.ReadElement(new CreditProgramSearchModel { Id = id })); + } + [HttpGet] + public IActionResult CurrencyPurchase() + { + if (APIClient.BankOperator == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + return View(_currencyPurchaseLogic.ReadList + (new CurrencyPurchaseSearchModel { BankOperatorId = APIClient.BankOperator.Id })); + } + [HttpGet] + public IActionResult CreateCurrencyPurchase() + { + if (APIClient.BankOperator == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + ViewBag.Currency = _currencyLogic.ReadList + (new CurrencySearchModel { BankOperatorId = APIClient.BankOperator.Id }); + return View(); + } + [HttpPost] + public void CreateCurrencyPurchasr(string amount, int currencyId) + { + if (APIClient.BankOperator == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } - OperatorId = APIClient.Operator.Id, - }); - Response.Redirect("Index"); + _currencyPurchaseLogic.Create(new CurrencyPurchaseBindingModel + { BankOperatorId = APIClient.BankOperator.Id, + Amount = (float)Convert.ToDouble(amount), + CurrencyId = currencyId }); + Response.Redirect("Transfers"); } } } \ No newline at end of file