public static async Task <T> GetObjectFor <T>(HttpResponseMessage response) { if (response.IsSuccessStatusCode) { var serialized = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <T>(serialized)); } else if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) { var errorMessage = await GetErrorMessage(response); string displayMessage = GetDisplayMessage(errorMessage); if (!string.IsNullOrWhiteSpace(displayMessage)) { UserDialogsHelper.ShowNotification(displayMessage.ToString(), NotificationTypeEnum.Error, TimeSpan.FromSeconds(3)); } } else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { LogOut?.Invoke(httpResponsHelper, new EventArgs()); } else if (response.StatusCode == System.Net.HttpStatusCode.Forbidden) { UserDialogsHelper.ShowNotification("There was an error in processing your request.", NotificationTypeEnum.Error); } else if (!response.IsSuccessStatusCode) { UserDialogsHelper.ShowNotification("There was an error while fetching data.", NotificationTypeEnum.Error); } return(default(T)); }
public static async Task <bool> IsConnectionAvailable() { if (Xamarin.Essentials.Connectivity.NetworkAccess == Xamarin.Essentials.NetworkAccess.Internet) { return(true); } else { UserDialogsHelper.ShowNotification("You are not connected to internet.", NotificationTypeEnum.Network, TimeSpan.FromSeconds(3)); return(false); } }
private async void GetUserDetails() { IsBusy = true; if (!string.IsNullOrWhiteSpace(UserName)) { User user = await _userApiClient.GetUser(UserName); if (user != null) { Preferences.Set(Constants.Keys.User, JsonConvert.SerializeObject(user)); await NavigationService.NavigateAsync($"/{nameof(HomePage)}"); } } else { UserDialogsHelper.ShowNotification("Username cannot be empty.", NotificationTypeEnum.Error); } IsBusy = false; }