Пример #1
0
        public async Task DeleteTodoItemAsync(UserToBack us)
        {
            var uri = new Uri(string.Format(Constants.DeleteUserUrl, us));

            try
            {
                var response = await _client.DeleteAsync(uri);

                if (response.IsSuccessStatusCode)
                {
                    Debug.WriteLine(@"\tTodoItem successfully deleted.");
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(@"\tERROR {0}", ex.Message);
            }
        }
Пример #2
0
        public async Task <HttpResponseMessage> SaveTodoItemAsync(UserToBack item, bool isNewItem)
        {
            var uri = new Uri(string.Format(Constants.RegisterUserUrl, string.Empty));

            try
            {
                var json    = JsonConvert.SerializeObject(item);
                var content = new StringContent(json, Encoding.UTF8, "application/json");

                HttpResponseMessage response = null;
                if (isNewItem)
                {
                    response = _client.PostAsync(uri, content).Result;
                    return(response);
                }
                else
                {
                    response = _client.PutAsync(uri, content).Result;
                    return(response);
                }

                if (response.IsSuccessStatusCode)
                {
                    Debug.WriteLine(@"\tTodoItem successfully saved.");
                }
                else
                {
                    Debug.WriteLine("registraione fallita");
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(@"\tERROR {0}", ex.Message);
                return(null);
            }
        }