diff --git a/BankYouBankrupt/BankYouBankruptCashierApp/APICashier.cs b/BankYouBankrupt/BankYouBankruptCashierApp/APICashier.cs index d6ac7cd..0428f0b 100644 --- a/BankYouBankrupt/BankYouBankruptCashierApp/APICashier.cs +++ b/BankYouBankrupt/BankYouBankruptCashierApp/APICashier.cs @@ -10,8 +10,10 @@ namespace BankYouBankruptCashierApp { private static readonly HttpClient _client = new(); - //Вью-модели, необходимые для дальнейшего генерирования запросов к апишке - public static CashierViewModel? Cashier { get; set; } = null; + public static string ErrorMessage = string.Empty; + + //Вью-модели, необходимые для дальнейшего генерирования запросов к апишке + public static CashierViewModel? Cashier { get; set; } = null; public static CreditingViewModel? Crediting { get; set; } = null; @@ -28,8 +30,13 @@ namespace BankYouBankruptCashierApp _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); } - //Get-запрос - public static T? GetRequest(string requestUrl) + public static void SetErrorMessage(string error) + { + ErrorMessage = error; + } + + //Get-запрос + public static T? GetRequest(string requestUrl) { var response = _client.GetAsync(requestUrl); var result = response.Result.Content.ReadAsStringAsync().Result; diff --git a/BankYouBankrupt/BankYouBankruptCashierApp/BankYouBankruptCashierApp.csproj b/BankYouBankrupt/BankYouBankruptCashierApp/BankYouBankruptCashierApp.csproj index ce17512..301879d 100644 --- a/BankYouBankrupt/BankYouBankruptCashierApp/BankYouBankruptCashierApp.csproj +++ b/BankYouBankrupt/BankYouBankruptCashierApp/BankYouBankruptCashierApp.csproj @@ -15,6 +15,10 @@ + + true + PreserveNewest + Always diff --git a/BankYouBankrupt/BankYouBankruptCashierApp/Controllers/HomeController.cs b/BankYouBankrupt/BankYouBankruptCashierApp/Controllers/HomeController.cs index 86a6269..c5caede 100644 --- a/BankYouBankrupt/BankYouBankruptCashierApp/Controllers/HomeController.cs +++ b/BankYouBankrupt/BankYouBankruptCashierApp/Controllers/HomeController.cs @@ -131,6 +131,13 @@ namespace BankYouBankruptCashierApp.Controllers }); } + [HttpGet] + public IActionResult ErrorPage() + { + return View(); + } + + #endregion #region Вход в приложение @@ -144,21 +151,23 @@ namespace BankYouBankruptCashierApp.Controllers //отсылаем указанные данные на проверку [HttpPost] - public void Enter(string login, string password) + public IActionResult Enter(string login, string password) { - if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) - { - throw new Exception("Введите логин и пароль"); - } + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) + { + APICashier.SetErrorMessage("Введите логин и пароль"); - APICashier.Cashier = APICashier.GetRequest($"/api/Cashier/Login?login={login}&password={password}"); + return Redirect("ErrorPage"); + } + + APICashier.Cashier = APICashier.GetRequest($"/api/Cashier/Login?login={login}&password={password}"); if (APICashier.Cashier == null) { throw new Exception("Неверный логин/пароль"); } - Response.Redirect("Index"); + return Redirect("Index"); } #endregion diff --git a/BankYouBankrupt/BankYouBankruptCashierApp/Views/Home/ErrorPage.cshtml b/BankYouBankrupt/BankYouBankruptCashierApp/Views/Home/ErrorPage.cshtml new file mode 100644 index 0000000..0bd80e2 --- /dev/null +++ b/BankYouBankrupt/BankYouBankruptCashierApp/Views/Home/ErrorPage.cshtml @@ -0,0 +1,10 @@ +@using BankYouBankruptCashierApp + +@{ + ViewData["Title"] = "Отправка отчета"; +} + +
+

Упс, что-то пошло не так...

+

Ошибка: @APICashier.ErrorMessage

+
\ No newline at end of file