Classasync.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Net;
  4. using System.Net.Http;
  5. using System.Net.Http.Headers;
  6. namespace BlazorApp
  7. {
  8. public class Classasync
  9. {
  10. public static bool userautorisate = false;
  11. static string? responseBody = null;
  12. public static List<BlazorApp.region> regions = new List<BlazorApp.region>();
  13. static string? responseBody1 = null;
  14. public static List<BlazorApp.ReciplentMessage> message = new List<BlazorApp.ReciplentMessage>();
  15. public static string passwordtrue;
  16. public static string addStatus = "";
  17. async public static Task getRegion()
  18. {
  19. using (var client = new HttpClient())
  20. {
  21. client.BaseAddress = new Uri("https://localhost:7018/");
  22. HttpResponseMessage response = await client.GetAsync("WeatherForecast");
  23. if (response.IsSuccessStatusCode)
  24. {
  25. responseBody = await response.Content.ReadAsStringAsync();
  26. regions = JsonConvert.DeserializeObject<List<BlazorApp.region>>(responseBody);
  27. }
  28. }
  29. }
  30. async public static Task getResiple()
  31. {
  32. using (var client = new HttpClient())
  33. {
  34. client.BaseAddress = new Uri("https://localhost:7018/");
  35. HttpResponseMessage response = await client.GetAsync("WeatherForecast/GetReciplentMessage");
  36. if (response.IsSuccessStatusCode)
  37. {
  38. responseBody1 = await response.Content.ReadAsStringAsync();
  39. message = JsonConvert.DeserializeObject<List<BlazorApp.ReciplentMessage>>(responseBody1);
  40. }
  41. }
  42. }
  43. async public static Task<bool> checkLoginAndPassword(string login, string password)
  44. {
  45. using (var client = new HttpClient())
  46. {
  47. var requestParams = new Dictionary<string, string>
  48. {
  49. {"login",login},
  50. {"password",password}
  51. };
  52. var requestUri = new Uri("https://localhost:7018/WeatherForecast/GetUserRole");
  53. var queryString = string.Join("&", requestParams.Select(param => $"{WebUtility.UrlEncode(param.Key)}={WebUtility.UrlEncode(param.Value)}"));
  54. var fullUri = $"{requestUri}?{queryString}";
  55. HttpResponseMessage response = await client.GetAsync(fullUri);
  56. if (response.IsSuccessStatusCode)
  57. {
  58. userautorisate = true;
  59. return true;
  60. }
  61. else
  62. {
  63. passwordtrue = "Вы ввели неверные данные для входа";
  64. return false;
  65. }
  66. }
  67. }
  68. async public static Task AddRegion(string region)
  69. {
  70. using (var client = new HttpClient())
  71. {
  72. var requestParams = new Dictionary<string, string>
  73. {
  74. {"region",region}
  75. };
  76. var requestUri = new Uri("https://localhost:7018/WeatherForecast/RegionUpdate");
  77. var queryString = string.Join("&", requestParams.Select(param => $"{WebUtility.UrlEncode(param.Key)}={WebUtility.UrlEncode(param.Value)}"));
  78. var fullUri = $"{requestUri}?{queryString}";
  79. HttpResponseMessage response = await client.GetAsync(fullUri);
  80. if (response.IsSuccessStatusCode)
  81. {
  82. }
  83. else
  84. {
  85. }
  86. }
  87. }
  88. async public static Task AddResiple(string resiple)
  89. {
  90. using (var client = new HttpClient())
  91. {
  92. var requestParams = new Dictionary<string, string>
  93. {
  94. {"RecipientMessage",resiple}
  95. };
  96. var requestUri = new Uri("https://localhost:7018/WeatherForecast/resipleUpdate");
  97. var queryString = string.Join("&", requestParams.Select(param => $"{WebUtility.UrlEncode(param.Key)}={WebUtility.UrlEncode(param.Value)}"));
  98. var fullUri = $"{requestUri}?{queryString}";
  99. HttpResponseMessage response = await client.GetAsync(fullUri);
  100. if (response.IsSuccessStatusCode)
  101. {
  102. }
  103. else
  104. {
  105. }
  106. }
  107. }
  108. }
  109. }