Exemple #1
0
        public void Delete(string action, int id)
        {
            HttpController http = new HttpController(ui);

            HttpResponseMessage message = http.Client.DeleteAsync(action + id).Result;

            message.EnsureSuccessStatusCode();
        }
Exemple #2
0
        public T Get <T>(string action, int?id = null)
        {
            HttpController http = new HttpController(ui);

            HttpResponseMessage message = http.Client.GetAsync(action + id).Result;

            message.EnsureSuccessStatusCode();
            string json = message.Content.ReadAsStringAsync().Result;

            return(JsonConvert.DeserializeObject <T>(json));
        }
Exemple #3
0
        public void Put <T>(string action, T item)
        {
            HttpController http    = new HttpController(ui);
            string         json    = JsonConvert.SerializeObject(item);
            HttpContent    content = new StringContent(json, Encoding.UTF8, "application/json");

            using (HttpResponseMessage message = http.Client.PutAsync(action, content).Result)
            {
                message.EnsureSuccessStatusCode();
                if (!message.IsSuccessStatusCode)
                {
                    throw new HttpRequestException();
                }
            }
        }
Exemple #4
0
        public T2 PutWithReturn <T, T2>(string action, T item)
        {
            HttpController http    = new HttpController(ui);
            string         json    = JsonConvert.SerializeObject(item);
            HttpContent    content = new StringContent(json, Encoding.UTF8, "application/json");

            using (HttpResponseMessage message = http.Client.PutAsync(action, content).Result)
            {
                message.EnsureSuccessStatusCode();
                if (!message.IsSuccessStatusCode)
                {
                    throw new HttpRequestException();
                }
                string json2 = message.Content.ReadAsStringAsync().Result;
                return(JsonConvert.DeserializeObject <T2>(json2));
            }
        }