Esempio n. 1
0
        /// <summary>
        /// Gets objects from the specified path.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="path">The path.</param>
        /// <returns></returns>
        public static async Task <T> Get <T>(string path)
        {
            try
            {
                HttpResponseMessage response = await client.GetAsync(uri + path);

                if (response.IsSuccessStatusCode)
                {
                    return(await response.Content.ReadAsAsync <T>());
                }
            }

            catch (Exception ex)
            {
                await Task.Run(() => ReportError.ErrorAsync(ex.Message));
            }
            return(default(T));
        }
Esempio n. 2
0
        /// <summary>
        /// Updates a generic object the specified path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="huntedAnimal">The hunted animal.</param>
        /// <returns></returns>
        public static async Task <bool> Update(string path, HuntedAnimal huntedAnimal)
        {
            HttpResponseMessage response = await client.PutAsJsonAsync(uri + path + huntedAnimal.HuntedAnimalId.ToString(), huntedAnimal);

            try
            {
                if (response.IsSuccessStatusCode)
                {
                    return(response.IsSuccessStatusCode);
                }
            }

            catch (Exception ex)
            {
                await Task.Run(() => ReportError.ErrorAsync(ex.Message));
            }
            return(false);
        }
Esempio n. 3
0
        /// <summary>
        /// Deletes  a generic the specified path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public static async Task <HttpStatusCode> Delete(string path, int id)
        {
            HttpResponseMessage response = await client.DeleteAsync(uri + path + id.ToString());

            try
            {
                if (response.IsSuccessStatusCode)
                {
                    return(response.StatusCode);
                }
            }
            catch (Exception ex)
            {
                await Task.Run(() => ReportError.ErrorAsync(ex.Message));
            }

            return(response.StatusCode);
        }