using Newtonsoft.Json; using System; using System.Net; using System.Net.Http; using System.Net.Http.Headers; namespace BlazorApp { public class Classasync { public static bool userautorisate = false; static string? responseBody = null; public static List regions = new List(); static string? responseBody1 = null; public static List message = new List(); public static string passwordtrue; public static string addStatus = ""; async public static Task getRegion() { using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://localhost:7018/"); HttpResponseMessage response = await client.GetAsync("WeatherForecast"); if (response.IsSuccessStatusCode) { responseBody = await response.Content.ReadAsStringAsync(); regions = JsonConvert.DeserializeObject>(responseBody); } } } async public static Task getResiple() { using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://localhost:7018/"); HttpResponseMessage response = await client.GetAsync("WeatherForecast/GetReciplentMessage"); if (response.IsSuccessStatusCode) { responseBody1 = await response.Content.ReadAsStringAsync(); message = JsonConvert.DeserializeObject>(responseBody1); } } } async public static Task checkLoginAndPassword(string login, string password) { using (var client = new HttpClient()) { var requestParams = new Dictionary { {"login",login}, {"password",password} }; var requestUri = new Uri("https://localhost:7018/WeatherForecast/GetUserRole"); var queryString = string.Join("&", requestParams.Select(param => $"{WebUtility.UrlEncode(param.Key)}={WebUtility.UrlEncode(param.Value)}")); var fullUri = $"{requestUri}?{queryString}"; HttpResponseMessage response = await client.GetAsync(fullUri); if (response.IsSuccessStatusCode) { userautorisate = true; return true; } else { passwordtrue = "Вы ввели неверные данные для входа"; return false; } } } async public static Task AddRegion(string region) { using (var client = new HttpClient()) { var requestParams = new Dictionary { {"region",region} }; var requestUri = new Uri("https://localhost:7018/WeatherForecast/RegionUpdate"); var queryString = string.Join("&", requestParams.Select(param => $"{WebUtility.UrlEncode(param.Key)}={WebUtility.UrlEncode(param.Value)}")); var fullUri = $"{requestUri}?{queryString}"; HttpResponseMessage response = await client.GetAsync(fullUri); if (response.IsSuccessStatusCode) { } else { } } } async public static Task AddResiple(string resiple) { using (var client = new HttpClient()) { var requestParams = new Dictionary { {"RecipientMessage",resiple} }; var requestUri = new Uri("https://localhost:7018/WeatherForecast/resipleUpdate"); var queryString = string.Join("&", requestParams.Select(param => $"{WebUtility.UrlEncode(param.Key)}={WebUtility.UrlEncode(param.Value)}")); var fullUri = $"{requestUri}?{queryString}"; HttpResponseMessage response = await client.GetAsync(fullUri); if (response.IsSuccessStatusCode) { } else { } } } } }