Ejemplo n.º 1
0
        private static HttpResponseMessage GetMethod(string patch)
        {
            HttpClient client = AdressList.GetHttpClient();

            AdminAuthorization.SetAuthorization(client);
            return(client.GetAsync(patch).Result);
        }
Ejemplo n.º 2
0
        private static void PostMethod(string patch, dynamic content, string name)
        {
            HttpClient client = AdressList.GetHttpClient();

            AdminAuthorization.SetAuthorization(client);
            HttpResponseMessage response = client.PostAsync(patch, content).Result;

            if (response.StatusCode == HttpStatusCode.Created)
            {
                NotifitactionForm.ShowMessage("Wysłany element: " + name);
            }
            else
            {
                DialogMessage.ShowInfo("Błąd wysyłania elementu: " + name);
            }
        }
Ejemplo n.º 3
0
        private static void DeleteMethod(string patch, int id, string name)
        {
            HttpClient client = AdressList.GetHttpClient();

            AdminAuthorization.SetAuthorization(client);
            string url = patch + "/" + id;
            HttpResponseMessage response = client.DeleteAsync(url).Result;

            if (response.StatusCode == HttpStatusCode.NoContent)
            {
                NotifitactionForm.ShowMessage("Usunięty element: " + name);
            }
            else
            {
                DialogMessage.ShowInfo("Błąd usuwania elemntu: " + name);
            }
        }
        public static void ChangeUserRole(User user)
        {
            HttpClient client = AdressList.GetHttpClient();

            AdminAuthorization.SetAuthorization(client);
            string patchUrl = AdressList.UsersAdmin + user.GetId() + "/update-role";
            var    content  = ContentCreator.CreateContent(user.GetRole());
            HttpResponseMessage response = client.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), patchUrl)
            {
                Content = content
            }).Result;

            if (response.StatusCode != HttpStatusCode.OK)
            {
                DialogMessage.ShowInfo("Problem ze zmianą statusu!");
            }
            else
            {
                NotifitactionForm.ShowMessage("Status zmieniony!");
            }
        }
        public static void BanUser(User user)
        {
            HttpClient client = AdressList.GetHttpClient();

            AdminAuthorization.SetAuthorization(client);
            string patchUrl = AdressList.UsersAdmin + user.GetId() + "/ban";
            HttpResponseMessage response = client.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), patchUrl)).Result;

            if (response.StatusCode != HttpStatusCode.NoContent)
            {
                DialogMessage.ShowInfo("Problem z banowaniem!");
            }
            else if (response.StatusCode == HttpStatusCode.Forbidden)
            {
                DialogMessage.ShowInfo("Nie można banować administratorów!");
            }
            else
            {
                NotifitactionForm.ShowMessage("Użytkownik zbanowany!");
            }
        }
        public static void ChangeArticleStatus(Article article)
        {
            HttpClient client = AdressList.GetHttpClient();

            AdminAuthorization.SetAuthorization(client);

            string patchUrl = AdressList.ArticlesAdmin + "/" + article.GetId() + "/status";
            var    content  = ContentCreator.CreateContent(article.GetStatus());
            HttpResponseMessage response = client.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), patchUrl)
            {
                Content = content
            }).Result;

            if (response.StatusCode != HttpStatusCode.OK)
            {
                DialogMessage.ShowInfo("Błąd zmiany statusu!");
            }
            else
            {
                NotifitactionForm.ShowMessage("Status zmieniony!");
            }
        }