public async Task InitializeAsync() { if (isBusy) { return; } isBusy = true; Jokes = new List <Joke>(); _jokeService = new JokeService(); if (!CrossConnectivity.Current.IsConnected) { DBJoke = new DatastoreJoke(); if (UserID > 0) { Jokes = DBJoke.GetMyJokes(UserID); } else { Jokes = DBJoke.GetAll().ToList(); } isBusy = false; return; } Jokes.Clear(); Jokes = await _jokeService.GetAsyncJokes(); isBusy = false; }
public async Task <Joke> GetJoke(string jokeid, bool likeSuccess) { Joke joke = new Joke(); if (!CrossConnectivity.Current.IsConnected) { return(joke); } var URL = Utils.PublicURL + "/api/joke?JokeID=" + jokeid; var _jokeDS = new DatastoreJoke(); var httpClient = new HttpClient(); var response = await httpClient.GetAsync(new Uri(URL)); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); joke = JsonConvert.DeserializeObject <Joke>(content); } if (likeSuccess) { _jokeDS.Update(joke); } return(await Task.FromResult <Joke>(joke)); }