public async void DeleteBrand(object sender, EventArgs e) { var menu = sender as MenuItem; var item = menu.CommandParameter as Brand; //or your type BrandsDelete brandsDelete = new BrandsDelete(item.BrandID); DeleteBrandCall(brandsDelete); }
private async void DeleteBrandCall(BrandsDelete brandsDelete) { string url = "http://dist.saluton.dk:7119/api/product/brands"; //"ttp://localhost:5000/api/session";//"https://localhost:5001/api/session"; //http://dist.saluton.dk:7119/api/session using (var client = new HttpClient()) using (var request = new HttpRequestMessage(HttpMethod.Delete, url)) { var json = JsonConvert.SerializeObject(brandsDelete); using (var stringContent = new StringContent(json, Encoding.UTF8, "application/json")) { request.Content = stringContent; using (var response = await client .SendAsync(request, HttpCompletionOption.ResponseHeadersRead) .ConfigureAwait(false)) { try { response.EnsureSuccessStatusCode(); Console.WriteLine("OK, brands deleted."); Device.BeginInvokeOnMainThread(() => { DisplayAlert("DELETE status", "Brand deleted succesfull", "OK"); }); } catch (HttpRequestException e) { Device.BeginInvokeOnMainThread(() => { DisplayAlert("Login status", "Wrong credentials", "OK"); }); } } } } }