From d666f1f74bf9d56176c50b6c63a7367b5dfabb57 Mon Sep 17 00:00:00 2001 From: ksenianeva <95441235+ksenianeva@users.noreply.github.com> Date: Sat, 20 May 2023 05:58:55 +0400 Subject: [PATCH 1/3] =?UTF-8?q?View=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D1=82?= =?UTF-8?q?=D1=87=D1=91=D1=82=D0=B0=20PDF.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/Home/ViewReport.cshtml | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 Bank/BankOperatorApp/Views/Home/ViewReport.cshtml diff --git a/Bank/BankOperatorApp/Views/Home/ViewReport.cshtml b/Bank/BankOperatorApp/Views/Home/ViewReport.cshtml new file mode 100644 index 0000000..f8d644c --- /dev/null +++ b/Bank/BankOperatorApp/Views/Home/ViewReport.cshtml @@ -0,0 +1,81 @@ +@using BankContracts.ViewModels + +@model List<ReportCurrencyPurchasePaymentViewModel> + +@{ + ViewData["Title"] = "View Report"; +} + +<div class="text-center"> + <h1 class="display-4">Отчёт о закупках</h1> + <h1 class="display4">C @ViewBag.DateFrom по @ViewBag.DateTo</h1> +</div> + + +<div class="text-center"> + @{ + if (Model == null) + { + <h3 class="display-4">Авторизируйтесь</h3> + return; + } + <table class="table"> + <thead> + <tr> + <th> + Номер закупки + </th> + <th> + Дата закупки + </th> + <th> + Валюта + </th> + <th> + Номер выплаты + </th> + <th> + Дата выплаты + </th> + </tr> + </thead> + <tbody> + @foreach (var item in Model) + { + <tr> + <td> + Закупка №@item.CurrencyPurchaseId + </td> + <td> + @Html.DisplayFor(modelItem => item.PurchaseDate) + </td> + <td> + @Html.DisplayFor(modelItem => item.CurrencyName) + </td> + <td> + </td> + <td> + </td> + </tr> + @foreach (var payment in item.Payments) + { + <tr> + <td> + </td> + <td> + </td> + <td> + </td> + <td> + Выплата №@payment.PaymentId + </td> + <td> + @Html.DisplayFor(modelItem => payment.PaymentDate) + </td> + </tr> + } + } + </tbody> + </table> + } +</div> \ No newline at end of file From fa9ade894192ec7100c862b5614eeb34d8531e96 Mon Sep 17 00:00:00 2001 From: ksenianeva <95441235+ksenianeva@users.noreply.github.com> Date: Sat, 20 May 2023 06:01:54 +0400 Subject: [PATCH 2/3] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=20APIC?= =?UTF-8?q?lient=20=D0=B8=D0=B7=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=B0=20"=D0=9F=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D1=89=D0=B8?= =?UTF-8?q?=D0=BA".?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bank/BankOperatorApp/APIClient.cs | 74 ------------------- .../Controllers/HomeController.cs | 61 +++++++-------- 2 files changed, 31 insertions(+), 104 deletions(-) delete mode 100644 Bank/BankOperatorApp/APIClient.cs diff --git a/Bank/BankOperatorApp/APIClient.cs b/Bank/BankOperatorApp/APIClient.cs deleted file mode 100644 index ed05568..0000000 --- a/Bank/BankOperatorApp/APIClient.cs +++ /dev/null @@ -1,74 +0,0 @@ -using BankContracts.ViewModels; -using System.Net.Http.Headers; -using System.Text; -using Newtonsoft.Json; - -namespace BankOperatorApp -{ - public class APIClient - { - private static readonly HttpClient _client = new(); - - public static BankOperatorViewModel? BankOperator { get; set; } = null; - - public static void Connect(IConfiguration configuration) - { - _client.BaseAddress = new Uri(configuration["IPAddress"]); - _client.DefaultRequestHeaders.Accept.Clear(); - _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - } - - public static T? GetRequest<T>(string requestUrl) - { - var response = _client.GetAsync(requestUrl); - var result = response.Result.Content.ReadAsStringAsync().Result; - if (response.Result.IsSuccessStatusCode) - { - return JsonConvert.DeserializeObject<T>(result); - } - else - { - throw new Exception(result); - } - } - - public static void PostRequest<T>(string requestUrl, T model) - { - var json = JsonConvert.SerializeObject(model); - var data = new StringContent(json, Encoding.UTF8, "application/json"); - - var response = _client.PostAsync(requestUrl, data); - - var result = response.Result.Content.ReadAsStringAsync().Result; - if (!response.Result.IsSuccessStatusCode) - { - throw new Exception(result); - } - } - - public static void PatchRequest<T>(string requestUrl, T model) - { - var json = JsonConvert.SerializeObject(model); - var data = new StringContent(json, Encoding.UTF8, "application/json"); - - var response = _client.PatchAsync(requestUrl, data); - - var result = response.Result.Content.ReadAsStringAsync().Result; - if (!response.Result.IsSuccessStatusCode) - { - throw new Exception(result); - } - } - - public static void DeleteRequest<T>(string requestUrl) - { - var response = _client.DeleteAsync(requestUrl); - - var result = response.Result.Content.ReadAsStringAsync().Result; - if (!response.Result.IsSuccessStatusCode) - { - throw new Exception(result); - } - } - } -} diff --git a/Bank/BankOperatorApp/Controllers/HomeController.cs b/Bank/BankOperatorApp/Controllers/HomeController.cs index 99e7adf..b0cb35f 100644 --- a/Bank/BankOperatorApp/Controllers/HomeController.cs +++ b/Bank/BankOperatorApp/Controllers/HomeController.cs @@ -20,6 +20,7 @@ namespace BankOperatorApp.Controllers private readonly ICurrencyPurchaseLogic _currencyPurchaseLogic; private readonly IReportLogic _reportLogic; private readonly AbstractMailWorker _mailWorker; + public static BankOperatorViewModel? BankOperator { get; set; } = null; public HomeController(ILogger<HomeController> logger, IBankOperatorLogic bankOperatorLogic, @@ -37,29 +38,29 @@ namespace BankOperatorApp.Controllers public IActionResult Index() { - if (APIClient.BankOperator == null) + if (HomeController.BankOperator == null) { return Redirect("~/Home/Enter"); } return View(_currencyLogic.ReadList(new CurrencySearchModel { BankOperatorId = - APIClient.BankOperator.Id })); + HomeController.BankOperator.Id })); } [HttpGet] public IActionResult Privacy() { - if (APIClient.BankOperator == null) + if (HomeController.BankOperator == null) { return Redirect("~/Home/Enter"); } - return View(APIClient.BankOperator); + return View(HomeController.BankOperator); } [HttpPost] public void Privacy(string login, string password, string lastname, string firstname, string middleName) { - if (APIClient.BankOperator == null) + if (HomeController.BankOperator == null) { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } @@ -69,7 +70,7 @@ namespace BankOperatorApp.Controllers } _bankOperatorLogic.Update(new BankOperatorBindingModel { - Id = APIClient.BankOperator.Id, + Id = HomeController.BankOperator.Id, LastName = lastname, FirstName = firstname, MiddleName = middleName, @@ -77,11 +78,11 @@ namespace BankOperatorApp.Controllers Password = password }); - APIClient.BankOperator.LastName = lastname; - APIClient.BankOperator.FirstName = firstname; - APIClient.BankOperator.MiddleName = middleName; - APIClient.BankOperator.Login = login; - APIClient.BankOperator.Password = password; + HomeController.BankOperator.LastName = lastname; + HomeController.BankOperator.FirstName = firstname; + HomeController.BankOperator.MiddleName = middleName; + HomeController.BankOperator.Login = login; + HomeController.BankOperator.Password = password; Response.Redirect("Index"); } @@ -105,9 +106,9 @@ namespace BankOperatorApp.Controllers { throw new Exception("Введите логин и пароль"); } - APIClient.BankOperator = _bankOperatorLogic.ReadElement + HomeController.BankOperator = _bankOperatorLogic.ReadElement (new BankOperatorSearchModel { Login = login, Password = password }); - if (APIClient.BankOperator == null) + if (HomeController.BankOperator == null) { throw new Exception("Неверный логин/пароль"); } @@ -150,25 +151,25 @@ namespace BankOperatorApp.Controllers [HttpPost] public void CreateCurrency(string name) { - if (APIClient.BankOperator == null) + if (HomeController.BankOperator == null) { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } _currencyLogic.Create(new CurrencyBindingModel { Name = name, - BankOperatorId = APIClient.BankOperator.Id, + BankOperatorId = HomeController.BankOperator.Id, }); Response.Redirect("Index"); } public IActionResult CreditPrograms() { - if (APIClient.BankOperator == null) + if (HomeController.BankOperator == null) { return Redirect("~/Home/Enter"); } return View(_creditProgramLogic.ReadList(new CreditProgramSearchModel - { BankOperatorId = APIClient.BankOperator.Id})); + { BankOperatorId = HomeController.BankOperator.Id})); } [HttpGet] public IActionResult CreateCreditProgram() @@ -179,7 +180,7 @@ namespace BankOperatorApp.Controllers [HttpPost] public void CreateCreditProgram(List<int> currencies, string name, float percent) { - if (APIClient.BankOperator == null) + if (HomeController.BankOperator == null) { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } @@ -190,7 +191,7 @@ namespace BankOperatorApp.Controllers if (currency != null) CurrencyCreditPrograms.Add(currency.Id, currency); } _creditProgramLogic.Create(new CreditProgramBindingModel { BankOperatorId = - APIClient.BankOperator.Id, + HomeController.BankOperator.Id, CreditProgramCurrencies = CurrencyCreditPrograms, Name = name, Percent = percent}); Response.Redirect("CreditPrograms"); } @@ -202,17 +203,17 @@ namespace BankOperatorApp.Controllers [HttpGet] public IActionResult CurrencyPurchase() { - if (APIClient.BankOperator == null) + if (HomeController.BankOperator == null) { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } return View(_currencyPurchaseLogic.ReadList - (new CurrencyPurchaseSearchModel { BankOperatorId = APIClient.BankOperator.Id })); + (new CurrencyPurchaseSearchModel { BankOperatorId = HomeController.BankOperator.Id })); } [HttpGet] public IActionResult CreateCurrencyPurchase() { - if (APIClient.BankOperator == null) + if (HomeController.BankOperator == null) { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } @@ -222,13 +223,13 @@ namespace BankOperatorApp.Controllers [HttpPost] public void CreateCurrencyPurchase(string amount, int currencyId) { - if (APIClient.BankOperator == null) + if (HomeController.BankOperator == null) { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } _currencyPurchaseLogic.Create(new CurrencyPurchaseBindingModel - { BankOperatorId = APIClient.BankOperator.Id, + { BankOperatorId = HomeController.BankOperator.Id, Amount = (float)Convert.ToDouble(amount), CurrencyId = currencyId, @@ -238,18 +239,18 @@ namespace BankOperatorApp.Controllers public IActionResult CurrencyPurchases() { - if (APIClient.BankOperator == null) + if (HomeController.BankOperator == null) { return Redirect("~/Home/Enter"); } return View(_currencyPurchaseLogic.ReadList(new CurrencyPurchaseSearchModel - { BankOperatorId = APIClient.BankOperator.Id })); + { BankOperatorId = HomeController.BankOperator.Id })); } [HttpGet] public IActionResult CurrencyReport() { - if (APIClient.BankOperator == null) + if (HomeController.BankOperator == null) { Response.WriteAsync($"<script language=\"javascript\">alert" + $"('You need to login!');window.location.replace('/Home/Enter');" + @@ -295,7 +296,7 @@ namespace BankOperatorApp.Controllers [HttpGet] public IActionResult CurrencyPurchasePaymentsReport() { - if (APIClient.BankOperator == null) + if (HomeController.BankOperator == null) { Response.WriteAsync($"<script language=\"javascript\">alert" + $"('You need to login!');window.location.replace('/Home/Enter');</script>"); @@ -307,7 +308,7 @@ namespace BankOperatorApp.Controllers public IActionResult CurrencyPurchasePaymentsReport(DateTime dateFrom, DateTime dateTo, string reptype, string email, string fileName) { - if (APIClient.BankOperator == null) + if (HomeController.BankOperator == null) { Response.WriteAsync($"<script language=\"javascript\">" + $"alert('You need to login!');window.location.replace('/Home/Enter');</script>"); @@ -329,7 +330,7 @@ namespace BankOperatorApp.Controllers _mailWorker.MailSendAsync(new MailSendInfoBindingModel { Subject = "Отчёт по закупкам", - Text = "Для оператора " + APIClient.BankOperator.LastName + APIClient.BankOperator.FirstName, + Text = "Для оператора " + HomeController.BankOperator.LastName + HomeController.BankOperator.FirstName, MailAddress = email, FileName = fileName, Attachment = report From 56f7e44dd496efe1e1b1ef67b9d9a15826d8cfcd Mon Sep 17 00:00:00 2001 From: ksenianeva <95441235+ksenianeva@users.noreply.github.com> Date: Sat, 20 May 2023 06:25:15 +0400 Subject: [PATCH 3/3] =?UTF-8?q?=D0=9F=D1=80=D0=B8=D0=B2=D1=8F=D0=B7=D0=BA?= =?UTF-8?q?=D0=B0=20"=D1=81=D0=B4=D0=B5=D0=BB=D0=BA=D0=B0-=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B3=D1=80=D0=B0=D0=BC=D0=BC=D0=B0".?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 58 ++++++++++++++++--- Bank/BankOperatorApp/Program.cs | 1 + .../Views/Home/AddDealsToCreditProgram.cshtml | 24 ++++++++ .../Views/Shared/_Layout.cshtml | 3 + 4 files changed, 79 insertions(+), 7 deletions(-) create mode 100644 Bank/BankOperatorApp/Views/Home/AddDealsToCreditProgram.cshtml diff --git a/Bank/BankOperatorApp/Controllers/HomeController.cs b/Bank/BankOperatorApp/Controllers/HomeController.cs index b0cb35f..49ee135 100644 --- a/Bank/BankOperatorApp/Controllers/HomeController.cs +++ b/Bank/BankOperatorApp/Controllers/HomeController.cs @@ -18,6 +18,7 @@ namespace BankOperatorApp.Controllers private readonly ICreditProgramLogic _creditProgramLogic; private readonly ICurrencyLogic _currencyLogic; private readonly ICurrencyPurchaseLogic _currencyPurchaseLogic; + private readonly IDealLogic _dealLogic; private readonly IReportLogic _reportLogic; private readonly AbstractMailWorker _mailWorker; public static BankOperatorViewModel? BankOperator { get; set; } = null; @@ -25,7 +26,8 @@ namespace BankOperatorApp.Controllers public HomeController(ILogger<HomeController> logger, IBankOperatorLogic bankOperatorLogic, ICreditProgramLogic creditProgramLogic, ICurrencyLogic currencyLogic, - ICurrencyPurchaseLogic currencyPurchaseLogic, IReportLogic reportLogic, AbstractMailWorker mailWorker) + ICurrencyPurchaseLogic currencyPurchaseLogic, IReportLogic reportLogic, + IDealLogic dealLogic, AbstractMailWorker mailWorker) { _logger = logger; _bankOperatorLogic = bankOperatorLogic; @@ -33,6 +35,7 @@ namespace BankOperatorApp.Controllers _currencyLogic = currencyLogic; _currencyPurchaseLogic = currencyPurchaseLogic; _reportLogic = reportLogic; + _dealLogic = dealLogic; _mailWorker = mailWorker; } @@ -110,7 +113,8 @@ namespace BankOperatorApp.Controllers (new BankOperatorSearchModel { Login = login, Password = password }); if (HomeController.BankOperator == null) { - throw new Exception("Неверный логин/пароль"); + Response.WriteAsync($"<script language=\"javascript\">alert('Wrong login or password!');window.location.replace('/Home/Enter');</script>"); + return; } Response.Redirect("Index"); } @@ -153,7 +157,9 @@ namespace BankOperatorApp.Controllers { if (HomeController.BankOperator == null) { - throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + Response.WriteAsync($"<script language=\"javascript\">" + + $"alert('You need to login!');window.location.replace('/Home/Enter');</script>"); + Redirect("/Home/Enter"); } _currencyLogic.Create(new CurrencyBindingModel { @@ -182,7 +188,9 @@ namespace BankOperatorApp.Controllers { if (HomeController.BankOperator == null) { - throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + Response.WriteAsync($"<script language=\"javascript\">" + + $"alert('You need to login!');window.location.replace('/Home/Enter');</script>"); + Redirect("/Home/Enter"); } Dictionary<int, ICurrencyModel> CurrencyCreditPrograms = new(); foreach (int id in currencies) @@ -205,7 +213,9 @@ namespace BankOperatorApp.Controllers { if (HomeController.BankOperator == null) { - throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + Response.WriteAsync($"<script language=\"javascript\">" + + $"alert('You need to login!');window.location.replace('/Home/Enter');</script>"); + return Redirect("/Home/Enter"); } return View(_currencyPurchaseLogic.ReadList (new CurrencyPurchaseSearchModel { BankOperatorId = HomeController.BankOperator.Id })); @@ -215,7 +225,9 @@ namespace BankOperatorApp.Controllers { if (HomeController.BankOperator == null) { - throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + Response.WriteAsync($"<script language=\"javascript\">" + + $"alert('You need to login!');window.location.replace('/Home/Enter');</script>"); + return Redirect("/Home/Enter"); } ViewBag.Currencies = _currencyLogic.ReadList(null); return View(); @@ -225,7 +237,9 @@ namespace BankOperatorApp.Controllers { if (HomeController.BankOperator == null) { - throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + Response.WriteAsync($"<script language=\"javascript\">" + + $"alert('You need to login!');window.location.replace('/Home/Enter');</script>"); + Redirect("/Home/Enter"); } _currencyPurchaseLogic.Create(new CurrencyPurchaseBindingModel @@ -345,5 +359,35 @@ namespace BankOperatorApp.Controllers return Redirect("/"); } } + + public IActionResult AddDealsToCreditProgram() + { + if (HomeController.BankOperator == null) + { + Response.WriteAsync($"<script language=\"javascript\">" + + $"alert('You need to login!');window.location.replace('/Home/Enter');</script>"); + return Redirect("/Home/Enter"); + } + ViewBag.CreditPrograms = _creditProgramLogic.ReadList(new CreditProgramSearchModel { BankOperatorId = HomeController.BankOperator.Id}); + ViewBag.Deals = _dealLogic.ReadList(null); + return View(); + } + + [HttpPost] + public void AddDealsToCreditProgram(int creditProgram, List<int> deals) + { + if (HomeController.BankOperator == null) + { + Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>"); + Redirect("/Home/Enter"); + } + foreach (var dealId in deals) + { + var deal = _dealLogic.ReadElement(new DealSearchModel { Id = dealId }); + if (deal != null) _dealLogic.Update(new DealBindingModel { Id = deal.Id, ClientId = deal.ClientId, CreditProgramId = creditProgram }); + } + Response.WriteAsync($"<script language=\"javascript\">alert('Success!');window.location.replace('/');</script>"); + Redirect("/"); + } } } \ No newline at end of file diff --git a/Bank/BankOperatorApp/Program.cs b/Bank/BankOperatorApp/Program.cs index f0dbb15..08918f7 100644 --- a/Bank/BankOperatorApp/Program.cs +++ b/Bank/BankOperatorApp/Program.cs @@ -33,6 +33,7 @@ builder.Services.AddTransient<ICurrencyLogic, CurrencyLogic>(); builder.Services.AddTransient<ICreditProgramLogic, CreditProgramLogic>(); builder.Services.AddTransient<IBankOperatorLogic, BankOperatorLogic>(); builder.Services.AddTransient<IReportLogic, ReportLogic>(); +builder.Services.AddTransient<IDealLogic, DealLogic>(); builder.Services.AddControllersWithViews(); diff --git a/Bank/BankOperatorApp/Views/Home/AddDealsToCreditProgram.cshtml b/Bank/BankOperatorApp/Views/Home/AddDealsToCreditProgram.cshtml new file mode 100644 index 0000000..e2d6f8e --- /dev/null +++ b/Bank/BankOperatorApp/Views/Home/AddDealsToCreditProgram.cshtml @@ -0,0 +1,24 @@ +@{ + 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="creditProgram" name="creditProgram" class="form-control" required asp-items="@(new SelectList(@ViewBag.CreditPrograms,"Id", "Name"))"></select> + </div> + </div> + <div class="row"> + <div class="col-4">Сделки:</div> + <div class="col-8"> + <select id="deals" name="deals" class="form-control" required multiple asp-items="@(new SelectList(@ViewBag.Deals,"Id", "DealDate"))"></select> + </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> \ No newline at end of file diff --git a/Bank/BankOperatorApp/Views/Shared/_Layout.cshtml b/Bank/BankOperatorApp/Views/Shared/_Layout.cshtml index 0f4ddb8..561b489 100644 --- a/Bank/BankOperatorApp/Views/Shared/_Layout.cshtml +++ b/Bank/BankOperatorApp/Views/Shared/_Layout.cshtml @@ -33,6 +33,9 @@ <li class="nav-item"> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="CurrencyPurchasePaymentsReport">Отчет по закупкам</a> </li> + <li class="nav-item"> + <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="AddDealsToCreditProgram">Привязка "сделка-программа"</a> + </li> <li class="nav-item"> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a> </li>