private async Task <ObservableCollection <Cmimet> > GetCmimet() { try { var response = await App.client.GetAsync(App.API_URL_BASE + "payments/cmimet"); if (response.StatusCode != System.Net.HttpStatusCode.OK) { UserDialogs.Instance.Alert("Probleme me server, Provoni Perseri", "Error", "Ok"); return(null); } else { var responseString = await response.Content.ReadAsStringAsync(); var cmimet = JsonConvert.DeserializeObject <ObservableCollection <Cmimet> >(responseString); Cmimet = cmimet; HasCmime = Cmimet.Any(); OnPropertyChanged("HasCmime"); return(Cmimet); } } catch (Exception e) { return(null); } }
private async Task CreateACmimAsync() { SelectedCmimi.SeasonID = SelectedSezoni.id; var json = JsonConvert.SerializeObject(SelectedCmimi); var g = json.Remove(1, 7); App.client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json"); HttpContent httpContent = new StringContent(g, Encoding.UTF8, "application/json"); var response = await App.client.PostAsync(App.API_URL_BASE + "payments/cmimet", httpContent); if (response.IsSuccessStatusCode) { UserDialogs.Instance.Alert("Cmimi u shtua me sukses", "Sukses", "OK"); } else { UserDialogs.Instance.Alert("Cmimi nuk u shtua me sukses", "Error", "OK"); } var responseString = await response.Content.ReadAsStringAsync(); Cmimet addedCmimet = JsonConvert.DeserializeObject <Cmimet>(responseString); Cmimet.Add(addedCmimet); HasCmime = Cmimet.Any(); OnPropertyChanged("HasCmime"); }