123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- 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<BlazorApp.region> regions = new List<BlazorApp.region>();
- static string? responseBody1 = null;
- public static List<BlazorApp.ReciplentMessage> message = new List<BlazorApp.ReciplentMessage>();
- public static string passwordtrue;
- public static string addStatus = "";
- async public static Task getRegion()
- {
- using (var client = new HttpClient())
- {
- client.BaseAddress = new Uri("https://localhost:7152/");
- HttpResponseMessage response = await client.GetAsync("WeatherForecast");
- if (response.IsSuccessStatusCode)
- {
- responseBody = await response.Content.ReadAsStringAsync();
- regions = JsonConvert.DeserializeObject<List<BlazorApp.region>>(responseBody);
- }
- }
- }
- async public static Task getResiple()
- {
- using (var client = new HttpClient())
- {
- client.BaseAddress = new Uri("https://localhost:7152/");
- HttpResponseMessage response = await client.GetAsync("WeatherForecast/GetReciplentMessage");
- if (response.IsSuccessStatusCode)
- {
- responseBody1 = await response.Content.ReadAsStringAsync();
- message = JsonConvert.DeserializeObject<List<BlazorApp.ReciplentMessage>>(responseBody1);
- }
- }
- }
- async public static Task<bool> checkLoginAndPassword(string login, string password)
- {
- using (var client = new HttpClient())
- {
- var requestParams = new Dictionary<string, string>
- {
- {"login",login},
- {"password",password}
- };
- var requestUri = new Uri("https://localhost:7152/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<string, string>
- {
- {"region",region}
- };
- var requestUri = new Uri("https://localhost:7152/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<string, string>
- {
- {"RecipientMessage",resiple}
- };
- var requestUri = new Uri("https://localhost:7152/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
- {
-
- }
- }
- }
-
- }
- }
|