Example #1
0
        public async Task <bool> AddChild(UserChilds child, string api_key)
        {
            client.BaseAddress = new Uri(ServerUrl);
            client.DefaultRequestHeaders.Clear();

            try
            {
                String JsonChild = JsonConvert.SerializeObject(child);
                var    content   = new StringContent(JsonChild, Encoding.UTF8, "application/json");
                var    response  = await client.PostAsync($"postchild/{api_key}", content);

                if (response.IsSuccessStatusCode)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                await App.Current.MainPage.DisplayAlert("Internet error", "Kan ikke forbinde til internettet", "OK");

                Debug.WriteLine(e);
            }

            return(false);
        }
Example #2
0
        private async void AddChild()
        {
            var api_key = (String)Application.Current.Properties["api_key"];

            // temp placeholder for testing.
            UserChilds tempChild = new UserChilds(0, Name, Birthday, api_key, Gender, 0);

            try
            {
                if (await Services.AddChild(tempChild, api_key) == true)
                {
                    MessagingCenter.Send <AddChildViewModel>(this, "update");
                    await NavService.PopToRoot();
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
        }