From f3cc5965a77b4a208a2a7cfd79f713c844a846fb Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Tue, 2 May 2023 13:41:34 +0400 Subject: [PATCH] ? --- .../BusinessLogics/OrderLogic.cs | 4 +- JewelryStoreClientApp/APIClient.cs | 78 ++++++++++--------- 2 files changed, 44 insertions(+), 38 deletions(-) diff --git a/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs b/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs index b24908e..03d7d2a 100644 --- a/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs @@ -48,7 +48,7 @@ namespace JewelryStoreBusinessLogic.BusinessLogics _logger.LogWarning("Insert operation failed"); return false; } - SendOrderMessage(result.ClientId, $"Установка ПО, Заказ №{result.Id}", $"Заказ №{result.Id} от {result.DateCreate} на сумму {result.Sum:0.00} принят"); + SendOrderMessage(result.ClientId, $"Магазин драгоценностей, Заказ №{result.Id}", $"Заказ №{result.Id} от {result.DateCreate} на сумму {result.Sum:0.00} принят"); return true; } @@ -89,7 +89,7 @@ namespace JewelryStoreBusinessLogic.BusinessLogics return false; } - SendOrderMessage(result.ClientId, $"Установка ПО, Заказ №{result.Id}", $"Заказ №{model.Id} изменен статус на {result.Status}"); + SendOrderMessage(result.ClientId, $"Магазин драгоценностей, Заказ №{result.Id}", $"Заказ №{model.Id} изменен статус на {result.Status}"); return true; } diff --git a/JewelryStoreClientApp/APIClient.cs b/JewelryStoreClientApp/APIClient.cs index 95389a1..d747788 100644 --- a/JewelryStoreClientApp/APIClient.cs +++ b/JewelryStoreClientApp/APIClient.cs @@ -5,41 +5,47 @@ using System.Text; namespace JewelryStoreClientApp { - public class APIClient - { - private static readonly HttpClient _client = new(); - public static ClientViewModel? Client { 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 class APIClient + { + private static readonly HttpClient _client = new(); - } + public static ClientViewModel? Client { 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); + } + } + } } + +