diff --git a/Bank/BankBusinessLogic/BusinessLogic/Cashier/AccountLogic.cs b/Bank/BankBusinessLogic/BusinessLogic/Cashier/AccountLogic.cs index e555d4d..c821dc7 100644 --- a/Bank/BankBusinessLogic/BusinessLogic/Cashier/AccountLogic.cs +++ b/Bank/BankBusinessLogic/BusinessLogic/Cashier/AccountLogic.cs @@ -60,7 +60,14 @@ namespace BankBusinessLogic.BusinessLogic.Cashier // Вывод всего списка счетов public List? ReadList(AccountSearchModel? model) { - _logger.LogInformation("ReadList. AccountNumber:{AccountNumber}. Id:{Id}", model.AccountNumber, model?.Id); + if (model != null) + { + _logger.LogInformation("ReadList. AccountNumber:{AccountNumber}. Id:{Id}", model.AccountNumber, model.Id); + } + else + { + _logger.LogInformation("ReadList without filter model"); + } // list хранит весь список в случае, если model пришло со значением null на вход метода var list = model == null ? _accountStorage.GetFullList() : _accountStorage.GetFilteredList(model); @@ -76,6 +83,7 @@ namespace BankBusinessLogic.BusinessLogic.Cashier return list; } + // Метод, отвечающий за изменение баланса счёта public bool ChangeBalance(AccountSearchModel? model, int sum) { diff --git a/Bank/BankCashierApp/APICashier.cs b/Bank/BankCashierApp/APICashier.cs index 42eba21..10a1d37 100644 --- a/Bank/BankCashierApp/APICashier.cs +++ b/Bank/BankCashierApp/APICashier.cs @@ -53,24 +53,24 @@ namespace BankCashierApp } } - //Post-запрос - public static void PostRequest(string requestUrl, T model) - { - var json = JsonConvert.SerializeObject(model); - var data = new StringContent(json, Encoding.UTF8, "application/json"); + //Post-запрос + 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 = _client.PostAsync(requestUrl, data); + var response = await _client.PostAsync(requestUrl, data); - var result = response.Result.Content.ReadAsStringAsync().Result; + if (!response.IsSuccessStatusCode) + { + var result = await response.Content.ReadAsStringAsync(); + throw new HttpRequestException($"Request failed with status code {response.StatusCode}: {result}"); + } + } - if (!response.Result.IsSuccessStatusCode) - { - throw new Exception(result); - } - } - //Post-запрос для получения данных - public static T? PostRequestReport(string requestUrl, U model) + //Post-запрос для получения данных + public static T? PostRequestReport(string requestUrl, U model) { var json = JsonConvert.SerializeObject(model); var data = new StringContent(json, Encoding.UTF8, "application/json");