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(string requestUrl) - { - var response = _client.GetAsync(requestUrl); - var result = response.Result.Content.ReadAsStringAsync().Result; - if (response.Result.IsSuccessStatusCode) - { - return JsonConvert.DeserializeObject(result); - } - else - { - throw new Exception(result); - } - } - - public static void PostRequest(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(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(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..49ee135 100644 --- a/Bank/BankOperatorApp/Controllers/HomeController.cs +++ b/Bank/BankOperatorApp/Controllers/HomeController.cs @@ -18,13 +18,16 @@ 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; public HomeController(ILogger 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; @@ -32,34 +35,35 @@ namespace BankOperatorApp.Controllers _currencyLogic = currencyLogic; _currencyPurchaseLogic = currencyPurchaseLogic; _reportLogic = reportLogic; + _dealLogic = dealLogic; _mailWorker = mailWorker; } 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 +73,7 @@ namespace BankOperatorApp.Controllers } _bankOperatorLogic.Update(new BankOperatorBindingModel { - Id = APIClient.BankOperator.Id, + Id = HomeController.BankOperator.Id, LastName = lastname, FirstName = firstname, MiddleName = middleName, @@ -77,11 +81,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,11 +109,12 @@ 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("Неверный логин/пароль"); + Response.WriteAsync($""); + return; } Response.Redirect("Index"); } @@ -150,25 +155,27 @@ namespace BankOperatorApp.Controllers [HttpPost] public void CreateCurrency(string name) { - if (APIClient.BankOperator == null) + if (HomeController.BankOperator == null) { - throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + Response.WriteAsync($""); + Redirect("/Home/Enter"); } _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,9 +186,11 @@ namespace BankOperatorApp.Controllers [HttpPost] public void CreateCreditProgram(List currencies, string name, float percent) { - if (APIClient.BankOperator == null) + if (HomeController.BankOperator == null) { - throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + Response.WriteAsync($""); + Redirect("/Home/Enter"); } Dictionary CurrencyCreditPrograms = new(); foreach (int id in currencies) @@ -190,7 +199,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,19 +211,23 @@ namespace BankOperatorApp.Controllers [HttpGet] public IActionResult CurrencyPurchase() { - if (APIClient.BankOperator == null) + if (HomeController.BankOperator == null) { - throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + Response.WriteAsync($""); + return Redirect("/Home/Enter"); } 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("Вы как суда попали? Суда вход только авторизованным"); + Response.WriteAsync($""); + return Redirect("/Home/Enter"); } ViewBag.Currencies = _currencyLogic.ReadList(null); return View(); @@ -222,13 +235,15 @@ namespace BankOperatorApp.Controllers [HttpPost] public void CreateCurrencyPurchase(string amount, int currencyId) { - if (APIClient.BankOperator == null) + if (HomeController.BankOperator == null) { - throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + Response.WriteAsync($""); + Redirect("/Home/Enter"); } _currencyPurchaseLogic.Create(new CurrencyPurchaseBindingModel - { BankOperatorId = APIClient.BankOperator.Id, + { BankOperatorId = HomeController.BankOperator.Id, Amount = (float)Convert.ToDouble(amount), CurrencyId = currencyId, @@ -238,18 +253,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($""); @@ -307,7 +322,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($""); @@ -329,7 +344,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 @@ -344,5 +359,35 @@ namespace BankOperatorApp.Controllers return Redirect("/"); } } + + public IActionResult AddDealsToCreditProgram() + { + if (HomeController.BankOperator == null) + { + Response.WriteAsync($""); + 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 deals) + { + if (HomeController.BankOperator == null) + { + Response.WriteAsync($""); + 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($""); + 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(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); 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"; +} +
+

Привязка сделок

+
+
+
+
Выплата:
+
+ +
+
+
+
Сделки:
+
+ +
+
+
+
+
+
+
\ No newline at end of file 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 + +@{ + ViewData["Title"] = "View Report"; +} + +
+

Отчёт о закупках

+

C @ViewBag.DateFrom по @ViewBag.DateTo

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

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

+ return; + } + + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + + @foreach (var payment in item.Payments) + { + + + + + + + + } + } + +
+ Номер закупки + + Дата закупки + + Валюта + + Номер выплаты + + Дата выплаты +
+ Закупка №@item.CurrencyPurchaseId + + @Html.DisplayFor(modelItem => item.PurchaseDate) + + @Html.DisplayFor(modelItem => item.CurrencyName) + + +
+ + + + Выплата №@payment.PaymentId + + @Html.DisplayFor(modelItem => payment.PaymentDate) +
+ } +
\ 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 @@ +