コード例 #1
0
        private async void RemoveReservation(object sender, EventArgs e)
        {
            var ReservationToRemove = (sender as MenuItem).CommandParameter as RezerwacjaModel;

            using (var HttpApiConnector = new HttpApiConnector().GetClient())
            {
                var Content         = JsonConvert.SerializeObject(ReservationToRemove);
                var ByteContent     = Encoding.UTF8.GetBytes(Content);
                var ByteArrayConent = new ByteArrayContent(ByteContent);
                ByteArrayConent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                HttpApiConnector.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Application.Current.Properties["token"].ToString());
                var request = new HttpRequestMessage
                {
                    Method     = HttpMethod.Delete,
                    RequestUri = new Uri(Constants.ConnectionApiUriRezerwacja + ReservationToRemove.ObjectId),
                    Content    = ByteArrayConent
                };
                var response = await HttpApiConnector.SendAsync(request);

                if (response.IsSuccessStatusCode)
                {
                    FutureReservations.Remove(ReservationToRemove);
                }
            }
        }
コード例 #2
0
        private async void DeleteUserAccount(object sender, EventArgs e)
        {
            using (var HtttpClientConnector = new HttpApiConnector().GetClient())
            {
                var PendingSend = Newtonsoft.Json.JsonConvert.SerializeObject(Main.User);
                var Buffer      = Encoding.UTF8.GetBytes(PendingSend);
                var byteContent = new ByteArrayContent(Buffer);
                byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                HtttpClientConnector.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Application.Current.Properties["token"].ToString());
                var request = new HttpRequestMessage
                {
                    Method     = HttpMethod.Delete,
                    RequestUri = new Uri(Constants.ConnectionApiUriUser),
                    Content    = byteContent,
                };
                var response = await HtttpClientConnector.SendAsync(request);

                if (response.IsSuccessStatusCode)
                {
                    await DisplayAlert("Sukces", "Udalo sie usunac konto", "Ok");
                }
            }
            Logout_Clicked(null, null);
        }