Beispiel #1
0
        public async Task Delete(string url, int id)
        {
            HttpResponseMessage response = await RestClientSingleton.Instance().DeleteAsync(url + id);

            string responseText = await response.Content.ReadAsStringAsync();

            response.Dispose();

            if (!response.IsSuccessStatusCode)
            {
                throw new Exception(responseText);
            }
        }
Beispiel #2
0
        public async Task Update(string url, int id, TEntity entity)
        {
            HttpContent         content  = new StringContent(JsonConvert.SerializeObject(entity), Encoding.UTF8, "application/json");
            HttpResponseMessage response = await RestClientSingleton.Instance().PutAsync(url + id, content);

            string responseText = await response.Content.ReadAsStringAsync();

            response.Dispose();

            if (!response.IsSuccessStatusCode)
            {
                throw new Exception(responseText);
            }
        }
Beispiel #3
0
        public async Task <IEnumerable <TEntity> > GetAll(string url)
        {
            HttpResponseMessage response = await RestClientSingleton.Instance().GetAsync(url);

            string responseText = await response.Content.ReadAsStringAsync();

            response.Dispose();

            if (!response.IsSuccessStatusCode)
            {
                throw new Exception(responseText);
            }

            return(JsonConvert.DeserializeObject <List <TEntity> >(responseText, new StringToNIntConverter()));
        }
Beispiel #4
0
        public async Task <TEntity> GetById(string url, int id)
        {
            string requestUri = url;

            if (id != 0)
            {
                requestUri += id;
            }

            HttpResponseMessage response = await RestClientSingleton.Instance().GetAsync(requestUri);

            string responseText = await response.Content.ReadAsStringAsync();

            response.Dispose();

            if (!response.IsSuccessStatusCode)
            {
                throw new Exception(responseText);
            }

            return(JsonConvert.DeserializeObject <TEntity>(responseText, new StringToNIntConverter()));
        }