コード例 #1
0
        public void Create(TimeToEvent Obj)
        {
            HttpClientHandler clientHandler = new HttpClientHandler();

            clientHandler.UseDefaultCredentials = true;
            using (var client = new HttpClient(clientHandler))
            {
                client.BaseAddress = new Uri(ServerUrl);
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                try
                {
                    var response = client.PostAsJsonAsync($"{RequestUri}", Obj).Result;
                }
                catch (Exception e)
                {
                    MessageDialogHelper.Show($"Ingen Forbindelse til serveren", "Server Fejl");
                }
            }
        }
コード例 #2
0
        public bool Update(Question Obj, int ID)
        {
            HttpClientHandler clientHandler = new HttpClientHandler();

            clientHandler.UseDefaultCredentials = true;
            using (var client = new HttpClient(clientHandler))
            {
                client.BaseAddress = new Uri(ServerUrl);
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                try
                {
                    return(client.PutAsJsonAsync <Question>($"{RequestUri}/{ID}", Obj).Result.IsSuccessStatusCode);
                }
                catch (Exception)
                {
                    MessageDialogHelper.Show($"Ingen Forbindelse til serveren", "Server Fejl");
                    return(false);
                }
            }
        }