From 225eee834904a3e8da241a865e3f70d76bac451b Mon Sep 17 00:00:00 2001 From: Allllen4a Date: Thu, 30 May 2024 03:02:48 +0400 Subject: [PATCH] =?UTF-8?q?=D1=8F=20=D0=BD=D0=B5=20=D0=BF=D0=BB=D0=B0?= =?UTF-8?q?=D1=87=D1=83=20=D1=8D=D1=82=D0=BE=20=D0=B4=D0=BE=D1=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BeautySalonDatabase.cs | 2 +- BeautySalonView/ClientWebApp/APIWorker.cs | 46 +++++++++---------- .../Controllers/HomeController.cs | 12 +++-- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/BeautySalonView/BeautySalonDatabaseImplement/BeautySalonDatabase.cs b/BeautySalonView/BeautySalonDatabaseImplement/BeautySalonDatabase.cs index c0cbff5..695ad24 100644 --- a/BeautySalonView/BeautySalonDatabaseImplement/BeautySalonDatabase.cs +++ b/BeautySalonView/BeautySalonDatabaseImplement/BeautySalonDatabase.cs @@ -17,7 +17,7 @@ namespace BeautySalonDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=PRETTYNAME;Initial Catalog=BeautySalonDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=ALYONA\;Initial Catalog=BeautySalonDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/BeautySalonView/ClientWebApp/APIWorker.cs b/BeautySalonView/ClientWebApp/APIWorker.cs index 7149cc2..28705a6 100644 --- a/BeautySalonView/ClientWebApp/APIWorker.cs +++ b/BeautySalonView/ClientWebApp/APIWorker.cs @@ -18,32 +18,32 @@ namespace WorkerWebApp _worker.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); } - public static T? GetRequest(string requestUrl) + public static async Task GetRequest(string requestUrl) + { + var response = await _worker.GetAsync(requestUrl); + var result = await response.Content.ReadAsStringAsync(); + if (response.IsSuccessStatusCode) { - var response = _worker.GetAsync(requestUrl); - var result = response.Result.Content.ReadAsStringAsync().Result; - if (response.Result.IsSuccessStatusCode) - { - return JsonConvert.DeserializeObject(result); - } - else - { - throw new Exception(result); - } + return JsonConvert.DeserializeObject(result); } - - public static void PostRequest(string requestUrl, T model) + else { - var json = JsonConvert.SerializeObject(model); - var data = new StringContent(json, Encoding.UTF8, "application/json"); - - var response = _worker.PostAsync(requestUrl, data); - - var result = response.Result.Content.ReadAsStringAsync().Result; - if (!response.Result.IsSuccessStatusCode) - { - throw new Exception(result); - } + throw new Exception(result); } } + + public static async Task PostRequest(string requestUrl, T model) + { + var json = JsonConvert.SerializeObject(model); + var data = new StringContent(json, Encoding.UTF8, "application/json"); + + var response = await _worker.PostAsync(requestUrl, data); + + var result = await response.Content.ReadAsStringAsync(); + if (!response.IsSuccessStatusCode) + { + throw new Exception(result); + } + } + } } \ No newline at end of file diff --git a/BeautySalonView/ClientWebApp/Controllers/HomeController.cs b/BeautySalonView/ClientWebApp/Controllers/HomeController.cs index 6f3c305..1fc6a76 100644 --- a/BeautySalonView/ClientWebApp/Controllers/HomeController.cs +++ b/BeautySalonView/ClientWebApp/Controllers/HomeController.cs @@ -76,21 +76,23 @@ namespace WorkerWebApp.Controllers return View(); } [HttpPost] - public void Enter(string login, string password) + public async Task Enter(string login, string password) { - if (string.IsNullOrEmpty(login) || - string.IsNullOrEmpty(password)) + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) { throw new Exception("Введите логин и пароль"); } - APIWorker.Worker = - APIWorker.GetRequest($"api/worker/login?login={login}&password={password}"); + + APIWorker.Worker = await APIWorker.GetRequest($"api/worker/login?login={login}&password={password}"); + if (APIWorker.Worker == null) { throw new Exception("Неверный логин/пароль"); } + Response.Redirect("Index"); } + [HttpGet] public IActionResult Register() {