From 9e270387b63af3365e9d1c513af677a4eb26999e Mon Sep 17 00:00:00 2001 From: "nikbel2004@outlook.com" Date: Tue, 28 May 2024 15:39:00 +0400 Subject: [PATCH] =?UTF-8?q?Stage=2011:=20ClientApp=20(=D0=94=D0=BE=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=BB=20HomeController,=20=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D1=8C=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82?= =?UTF-8?q?=D1=8B,=20=D0=BD=D0=B0=D0=B4=D0=BE=20=D0=B4=D0=BE=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B0=D1=82=D1=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bank/BankClientApp/APIClient.cs | 2 +- .../Controllers/HomeController.cs | 619 +++++++++++++++++- Bank/BankClientApp/Program.cs | 4 + Bank/BankClientApp/Views/Home/Privacy.cshtml | 2 +- Bank/BankClientApp/Views/Home/Register.cshtml | 2 +- 5 files changed, 601 insertions(+), 28 deletions(-) diff --git a/Bank/BankClientApp/APIClient.cs b/Bank/BankClientApp/APIClient.cs index fa1c0c0..684f1cc 100644 --- a/Bank/BankClientApp/APIClient.cs +++ b/Bank/BankClientApp/APIClient.cs @@ -60,7 +60,7 @@ namespace BankClientApp } // Post-запрос для получения данных - public static T? PostRequetReport(string requestUrl, U model) + public static T? PostRequestReport(string requestUrl, U model) { var json = JsonConvert.SerializeObject(model); var data = new StringContent(json, Encoding.UTF8, "application/json"); diff --git a/Bank/BankClientApp/Controllers/HomeController.cs b/Bank/BankClientApp/Controllers/HomeController.cs index f15265d..f7fbbac 100644 --- a/Bank/BankClientApp/Controllers/HomeController.cs +++ b/Bank/BankClientApp/Controllers/HomeController.cs @@ -1,4 +1,12 @@ using BankClientApp.Models; +using BankContracts.BindingModels.Client; +using BankContracts.BindingModels.Reports; +using BankContracts.ViewModels; +using BankContracts.ViewModels.Client.Diagram; +using BankContracts.ViewModels.Client.ViewModels; +using BankContracts.ViewModels.Reports; +using BankContracts.ViewModels.Reports.Client; +using BankDataModels.Enums; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; @@ -13,70 +21,631 @@ namespace BankClientApp.Controllers _logger = logger; } + // Профиль, вход и регистрация public IActionResult Index() { return View(); } - public IActionResult Privacy() - { - return View(); - } - + [HttpGet] public IActionResult Enter() { return View(); } + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + public IActionResult Error() + { + return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + } + + [HttpGet] + public IActionResult ErrorPage() + { + return View(); + } + + // Логин и регистрация + + [HttpGet] public IActionResult Login() { return View(); } + [HttpPost] + public IActionResult Login(string login, string password) + { + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) + { + APIClient.SetErrorMessage("Введите логин и пароль"); + + return Redirect("ErrorPage"); + } + + APIClient.Client = APIClient.GetRequest($"api/Client/Logn?login={login}&password={password}"); + + if (APIClient.Client == null) + { + APIClient.SetErrorMessage("Неверный логин и пароль"); + + return Redirect("ErrorPage"); + } + + return Redirect("Enter"); + } + + [HttpGet] public IActionResult Register() { return View(); } + [HttpPost] + public void Register(string login, string password, string name, string surname, string patronymic, string mobilephone) + { + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(name) + || string.IsNullOrEmpty(surname) || string.IsNullOrEmpty(patronymic) || string.IsNullOrEmpty(mobilephone)) + { + APIClient.SetErrorMessage("Проверьте правильность заполнения полей"); + + Response.Redirect("ErrorPage"); + } + + APIClient.PostRequest("api/Client/Register", new ClientBindingModel + { + Name = name, + Surname = surname, + Patronymic = patronymic, + Email = login, + Password = password, + MobilePhone = mobilephone + }); + + Response.Redirect("Enter"); + + return; + } + + [HttpPost] + public IActionResult Logout() + { + APIClient.Client = null; + + return Redirect("~/Home/Enter"); + } + + public IActionResult Privacy() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + + return View(APIClient.Client); + } + + [HttpPost] + public void Privacy(string login, string password, string name, string surname, string patronymic, string mobilephone) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(name) + || string.IsNullOrEmpty(surname) || string.IsNullOrEmpty(patronymic) || string.IsNullOrEmpty(mobilephone)) + { + APIClient.SetErrorMessage("Проверьте правильность заполнения полей"); + + Response.Redirect("ErrorPage"); + } + + APIClient.PostRequest("/api/Client/UpdateData", new ClientBindingModel + { + Id = APIClient.Client.Id, + Name = name, + Surname = surname, + Patronymic = patronymic, + MobilePhone = mobilephone, + Email = login, + Password = password + }); + + APIClient.Client.Name = name; + APIClient.Client.Surname = surname; + APIClient.Client.Patronymic = patronymic; + APIClient.Client.Email = login; + APIClient.Client.Password = password; + APIClient.Client.MobilePhone = mobilephone; + + Response.Redirect("Enter"); + + } + + // Банковские карты, работа с картами // + + [HttpGet] + public IActionResult CardsList() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + + return View(APIClient.GetRequest>($"api/Card/GetUsersCardsList?id={APIClient.Client.Id}")); + } + + [HttpGet] public IActionResult CreateCard() { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Accounts = APIClient.GetRequest>($"api/Account/SearchAccountsOfCLient?clientId={APIClient.Client.Id}"); return View(); } + [HttpPost] + public IActionResult CreateCard(string accountId, string number, string cvc, DateTime period) + { + if (APIClient.Client == null) + { + APIClient.SetErrorMessage("Необходимо авторизоваться"); + + return Redirect("ErrorPage"); + } + + if (string.IsNullOrEmpty(accountId) || string.IsNullOrEmpty(number) || string.IsNullOrEmpty(cvc) + || period.Year == 0001 || period <= DateTime.Now) + { + APIClient.SetErrorMessage("Проверьте корректность параметров создаваемой карты"); + + return Redirect("ErrorPage"); + } + + APIClient.PostRequest("api/Card/CreateCard", new CardBindingModel + { + Id = APIClient.Client.Id, + AccountId = int.Parse(accountId), + Number = number, + Period = period, + StatusCard = StatusCard.Открыта + }); + + return Redirect("~/Home/CardsList"); + } + + + // Снятие средств с банковской карты + + [HttpGet] + public IActionResult DebitingList() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + + return View(APIClient.GetRequest>($"api/Client/getUsersDebitings?userId={APIClient.Client.Id}")); + } + + [HttpGet] + public IActionResult CreateDebiting() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Cards = APIClient.GetRequest>($"api/Card/GetUsersCardsList?id={APIClient.Client.Id}"); + return View(); + } + + [HttpPost] + public IActionResult CreateDebiting(string cardId, int sum) + { + if (APIClient.Client == null) + { + APIClient.SetErrorMessage("Необходимо авторизоваться"); + + return Redirect("ErrorPage"); + } + + if (string.IsNullOrEmpty(cardId) || sum <= 0) + { + APIClient.SetErrorMessage("Необходимо ввести корректную сумму для снятия"); + + return Redirect("ErrorPage"); + } + + APIClient.PostRequest("api/Card/CreateDebitingRequest", new DebitingBindingModel() + { + CardId = int.Parse(cardId), + Sum = sum, + //DateOpen = DateTime.Now, + //Status = StatusEnum.Открыта + }); + + return Redirect("~/Home/DebitingList"); + } + + // === Пополнение средств === // + + [HttpGet] + public IActionResult CreditingList() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + + return View(APIClient.GetRequest>($"api/Client/getUsersCreditings?userId={APIClient.Client.Id}")); + } + + [HttpGet] + public IActionResult CreateCrediting() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Cards = APIClient.GetRequest>($"api/Card/GetUsersCardsList?id={APIClient.Client.Id}"); + return View(); + } + + [HttpPost] + public IActionResult CreateCrediting(string cardId, int sum) + { + if (APIClient.Client == null) + { + throw new Exception("Не авторизованы"); + } + + if (string.IsNullOrEmpty(cardId) || sum <= 0) + { + APIClient.SetErrorMessage("Необходимо ввести корректную сумму для пополнения"); + + return Redirect("ErrorPage"); + } + + APIClient.PostRequest("api/Card/CreateCreditingOperation", new CreditingBindingModel() + { + CardId = int.Parse(cardId), + Sum = sum, + //DateOpen = DateTime.Now, + //Status = StatusEnum.Открыта + }); + + return Redirect("~/Home/CreditingList"); + } + + //=== Получение отчёта PDF ===// + + [HttpGet] public IActionResult CreateReport() { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(); } - public IActionResult ReportBankCard() + [HttpPost] + public IActionResult CreateReport(DateTime dateFrom, DateTime dateTo) { - return View(); + if (APIClient.Client == null) + { + throw new Exception("Не авторизованы"); + } + + if (dateFrom == dateTo || dateFrom > dateTo || dateFrom.Year == 0001 || dateTo.Year == 0001) + { + APIClient.SetErrorMessage("Необходимо задать корректные границы периода"); + + return Redirect("ErrorPage"); + } + + return View(APIClient.PostRequestReport("api/Report/CreateClientReport", new ReportSupportBindingModel() + { + DateFrom = dateFrom, + DateTo = dateTo, + Email = APIClient.Client.Email + })); } - public IActionResult Crediting() - { - return View(); - } + //=== Excel отчёты ===// - public IActionResult Debiting() - { - return View(); - } - - public IActionResult MoneyTransfers() + // Отчёт клиента по переводам + [HttpPost] + public IActionResult CreateExcelReport(List cards) { - return View(); + if (APIClient.Client == null) + { + APIClient.SetErrorMessage("Не авторизованы"); + + return Redirect("ErrorPage"); + } + + if (cards.Count == 0 || cards.Count == cards.Where(x => x.IsChecked == false).ToList().Count) + { + APIClient.SetErrorMessage("Необходимо выбрать хотя-бы 1 карту для отчёта"); + + return Redirect("ErrorPage"); + } + + APIClient.PostRequest("api/Report/CreateExcelClient", new ReportSupportBindingModel() + { + CardList = cards.Where(x => x.IsChecked).Select(x => x.Id).ToList(), + Email = APIClient.Client.Email + }); + + return Redirect("ReportSuccess"); } - public IActionResult Cards() + // Отчёт клиента по пополнениям + [HttpPost] + public IActionResult CreateCreditingExcelReport(List cards) { + if (APIClient.Client == null) + { + APIClient.SetErrorMessage("Не авторизованы"); + + return Redirect("ErrorPage"); + } + + if (cards.Count == 0 || cards.Count == cards.Where(x => x.IsChecked == false).ToList().Count) + { + APIClient.SetErrorMessage("Необходимо выбрать хотя-бы 1 карту для отчёта"); + + return Redirect("ErrorPage"); + } + + APIClient.PostRequest("api/Report/CreateExcelCrediting", new ReportSupportBindingModel() + { + CardList = cards.Where(x => x.IsChecked).Select(x => x.Id).ToList(), + Email = APIClient.Client.Email + }); + + return Redirect("ReportSuccess"); + } + + // Отчёт клиента по снятиям + [HttpPost] + public IActionResult CreateDebitingExcelReport(List cards) + { + if (APIClient.Client == null) + { + APIClient.SetErrorMessage("Не авторизованы"); + + return Redirect("ErrorPage"); + } + + if (cards.Count == 0 || cards.Count == cards.Where(x => x.IsChecked == false).ToList().Count) + { + APIClient.SetErrorMessage("Необходимо выбрать хотя-бы 1 карту для отчёта"); + + return Redirect("ErrorPage"); + } + + APIClient.PostRequest("api/Report/CreateExcelDebiting", new ReportSupportBindingModel() + { + CardList = cards.Where(x => x.IsChecked).Select(x => x.Id).ToList(), + Email = APIClient.Client.Email + }); + + return Redirect("ReportSuccess"); + } + + //=== Word отчёты клиента ===// + + // Отчёт клиента по переводам + [HttpPost] + public IActionResult CreateWordReport(List cards) + { + if (APIClient.Client == null) + { + APIClient.SetErrorMessage("Не авторизованы"); + + return Redirect("ErrorPage"); + } + + if (cards.Count == 0 || cards.Count == cards.Where(x => x.IsChecked == false).ToList().Count) + { + APIClient.SetErrorMessage("Необходимо выбрать хотя-бы 1 карту для отчёта"); + + return Redirect("ErrorPage"); + } + + APIClient.PostRequest("api/Report/CreateWordClient", new ReportSupportBindingModel() + { + CardList = cards.Where(x => x.IsChecked).Select(x => x.Id).ToList(), + Email = APIClient.Client.Email + }); + + return Redirect("ReportSuccess"); + } + + // Отчёт клиента по пополнениям + [HttpPost] + public IActionResult CreateCreditingWordReport(List cards) + { + if (APIClient.Client == null) + { + APIClient.SetErrorMessage("Не авторизованы"); + + return Redirect("ErrorPage"); + } + + if (cards.Count == 0 || cards.Count == cards.Where(x => x.IsChecked == false).ToList().Count) + { + APIClient.SetErrorMessage("Необходимо выбрать хотя-бы 1 карту для отчёта"); + + return Redirect("ErrorPage"); + } + + APIClient.PostRequest("api/Report/CreateWordCrediting", new ReportSupportBindingModel() + { + CardList = cards.Where(x => x.IsChecked).Select(x => x.Id).ToList(), + Email = APIClient.Client.Email + }); + + return Redirect("ReportSuccess"); + } + + // Отчёт клиента по снятиям + [HttpPost] + public IActionResult CreateDebitingWordReport(List cards) + { + if (APIClient.Client == null) + { + APIClient.SetErrorMessage("Не авторизованы"); + + return Redirect("ErrorPage"); + } + + if (cards.Count == 0 || cards.Count == cards.Where(x => x.IsChecked == false).ToList().Count) + { + APIClient.SetErrorMessage("Необходимо выбрать хотя-бы 1 карту для отчёта"); + + return Redirect("ErrorPage"); + } + + APIClient.PostRequest("api/Report/CreateWordDebiting", new ReportSupportBindingModel() + { + CardList = cards.Where(x => x.IsChecked).Select(x => x.Id).ToList(), + Email = APIClient.Client.Email + }); + + return Redirect("ReportSuccess"); + } + + // === Получение отчета по картам === // + + [HttpGet] + public IActionResult ReportWithCards() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + + return View(new ReportClientCardsViewModel() + { + Cards = APIClient.GetRequest>($"api/Card/GetUsersCardsList?id={APIClient.Client.Id}").Select(x => new CheckboxViewModel() + { + Id = x.Id, + LabelName = x.Number, + IsChecked = false + }).ToList() + }); + } + + [HttpPost] + public IActionResult ReportWithCards(List cards) + { + if (APIClient.Client == null) + { + APIClient.SetErrorMessage("Не авторизованы"); + + return Redirect("ErrorPage"); + } + + if (cards.Count == 0 || cards.Count == cards.Where(x => x.IsChecked == false).ToList().Count) + { + APIClient.SetErrorMessage("Необходимо выбрать хотя-бы 1 карту для отчёта"); + + return Redirect("ErrorPage"); + } + + List cardList = cards.Where(x => x.IsChecked).Select(x => x.Id).ToList(); + + //List creditings = APIClient.GetRequest>($"api/Client/getUsersCreditings?userId={APIClient.Client.Id}") + // .Where(x => cardList.Contains(x.CardId)).Select(x => new ReportViewModel() + // { + // Id = x.Id, + // CardId = x.CardId, + // // DateOpen = x.DateOpen, + // // DateClose = x.DateClose, + // CardNumber = x.CardNumber, + // //Status = x.Status, + // Sum = x.Sum, + // TypeOperation = TypeOperationEnum.Пополнение + // }).ToList(); + + //List debitings = APIClient.GetRequest>($"api/Client/getUsersDebitings?userId={APIClient.Client.Id}") + // .Where(x => cardList.Contains(x.CardId)).Select(x => new ReportViewModel() + // { + // Id = x.Id, + // CardId = x.CardId, + // DateOpen = x.DateOpen, + // DateClose = x.DateClose, + // CardNumber = x.CardNumber, + // Status = x.Status, + // Sum = x.Sum, + // TypeOperation = TypeOperationEnum.Снятие + // }).ToList(); + + //List result = creditings.Concat(debitings).OrderBy(x => x.DateOpen).ToList(); + + return View(new ReportClientCardsViewModel() + { + Cards = cards, + //Operations = result, + }); + } + + // === Диаграмма === // + + [HttpGet] + public IActionResult Diagram() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Cards = APIClient.GetRequest>($"api/Card/GetUsersCardsList?id={APIClient.Client.Id}"); + return View(); } - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - public IActionResult Error() - { - return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); - } - } + [HttpPost] + public IActionResult Diagram(int cardId) + { + if (APIClient.Client == null) + { + APIClient.SetErrorMessage("Не авторизованы"); + + return Redirect("ErrorPage"); + } + + ViewBag.Cards = APIClient.GetRequest>($"api/Card/GetUsersCardsList?id={APIClient.Client.Id}"); + + return View(new ClientDiagramViewModel() + { + DiagramName = "Hello World", + Elements = APIClient.GetRequest>($"api/Card/getCardMonthResult?cardId={cardId}") + }); + } + + // Сообщение об успешной отправке отчёта на почту + [HttpGet] + public IActionResult ReportSuccess() + { + if (APIClient.Client == null) + { + APIClient.SetErrorMessage("Не авторизованы"); + + return Redirect("ErrorPage"); + } + + return View(); + } + } } diff --git a/Bank/BankClientApp/Program.cs b/Bank/BankClientApp/Program.cs index 559dd3a..a702470 100644 --- a/Bank/BankClientApp/Program.cs +++ b/Bank/BankClientApp/Program.cs @@ -1,3 +1,5 @@ +using BankClientApp; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. @@ -5,6 +7,8 @@ builder.Services.AddControllersWithViews(); var app = builder.Build(); +APIClient.Connect(builder.Configuration); + // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { diff --git a/Bank/BankClientApp/Views/Home/Privacy.cshtml b/Bank/BankClientApp/Views/Home/Privacy.cshtml index 9f1ac2b..0d57090 100644 --- a/Bank/BankClientApp/Views/Home/Privacy.cshtml +++ b/Bank/BankClientApp/Views/Home/Privacy.cshtml @@ -29,7 +29,7 @@
Телефон:
- Model.MobilePhone) required> + Model.MobilePhone) required>
diff --git a/Bank/BankClientApp/Views/Home/Register.cshtml b/Bank/BankClientApp/Views/Home/Register.cshtml index 411581b..562401e 100644 --- a/Bank/BankClientApp/Views/Home/Register.cshtml +++ b/Bank/BankClientApp/Views/Home/Register.cshtml @@ -12,7 +12,7 @@ - +