/// <summary> /// Loads the user profile. /// </summary> private async Task LoadUserProfile() { this.IsRunning = true; try { var connection = await this.apiService.CheckConnection(); if (!connection.IsSuccess) { this.IsRunning = false; await Application.Current.MainPage.DisplayAlert( Languages.Error, connection.Message, Languages.Cancel); //this.BackToLoginPage(); return; } //EndPoint API Call var response = await this.apiService.Get <UserBasicProfile>( urlBase : Settings.UrlBaseApiSigob, servicePrefix : App.PrefixApiSigob, controller : apiProfileController, authToken : Settings.Token, authDbToken : Settings.DbToken ); if (!response.IsSuccess) { this.IsRunning = false; await Application.Current.MainPage.DisplayAlert( Languages.Error, response.Message, Languages.Cancel); //this.BackToLoginPage(); return; } this.userProfile = (UserBasicProfile)response.Result; BindingUserObject(); //Assign Profile values to Image and TableView components if (!string.IsNullOrEmpty(userProfile.UserImage)) { byte[] userImageStream = Convert.FromBase64String(this.userProfile.UserImage); ImageSource = ImageSource.FromStream(() => new MemoryStream(userImageStream)); } else { ImageSource = (userProfile.Gender == 2) ? ImageSource.FromFile("ic_avatar_women") : ImageSource.FromFile("ic_avatar_men"); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } finally { this.IsRunning = false; } }
/// <summary> /// Loads the name of the user image. /// </summary> private async Task LoadBasicProfileData() { this.IsRunning = true; var connection = await this.apiService.CheckConnection(); if (!connection.IsSuccess) { this.IsRunning = false; if (Application.Current.MainPage != null) { await Application.Current.MainPage.DisplayAlert( Languages.Error, connection.Message, Languages.Cancel); } this.BackToLoginPage(); return; } //EndPoint API Call var response = await this.apiService.Get <UserBasicProfile>( urlBase : Settings.UrlBaseApiSigob, servicePrefix : App.PrefixApiSigob, controller : apiProfileController, authToken : Settings.Token, authDbToken : Settings.DbToken ); if (!response.IsSuccess) { this.IsRunning = false; var apiErrorResult = response.Result; await Xamarin.Forms.Application.Current.MainPage.DisplayAlert( Languages.Error, response.Message, Languages.Cancel); this.BackToLoginPage(); return; } this.profile = (UserBasicProfile)response.Result; //Assign Profile values Full Name and User Image this.UserFullName = $"{profile.FirstName} {profile.LastName}"; if (!string.IsNullOrEmpty(profile.UserImage)) { byte[] userImageStream = Convert.FromBase64String(this.profile.UserImage); ImageSource = ImageSource.FromStream(() => new MemoryStream(userImageStream)); } else { ImageSource = ImageSource.FromFile("ic_avatar_men"); } //Institution Logo if (!string.IsNullOrEmpty(Settings.InstitutionLogo)) { byte[] logoImageStream = Convert.FromBase64String(Settings.InstitutionLogo); InstitutionLogo = ImageSource.FromStream(() => new MemoryStream(logoImageStream)); } else { InstitutionLogo = ImageSource.FromFile("ic_sigob_logo"); } this.IsRunning = false; }