private async Task SubmitHandlerAsync() { this.IsBusy = true; var hasError = false; try { this.User = await this.User.SaveAsync() as IUser; var identity = await this.userIdentityObjectFactory.FetchAsync(this.User.ProfileID); var principal = new CslaPrincipalCore(identity); Csla.ApplicationContext.User = principal; } catch (DataPortalException ex) { this.logger.Log(ex); hasError = true; } this.IsBusy = false; if (!hasError) { // Always navigate to the Polls page first. this.ShowViewModel <PollsPageViewModel>(); // If there is a PollId, the user is coming in from a URI link. // Navigate to the View Poll page, leaving the Polls page in the back // stack so the user can back up to it. if (this.NavigationCriteria.PollId.HasValue) { this.Close(this); } #if MOBILE ChangePresentation(new ClearBackstackHint()); #endif } else { await this.messageBox.ShowAsync("There was an error saving your profile. Please try again.", "Error"); } }
private async Task LoadIdentityAndGo(string profileId) { IUserIdentity identity = null; IsBusy = true; try { identity = await this.objectFactory.FetchAsync(profileId); var principal = new CslaPrincipalCore(identity); Csla.ApplicationContext.User = principal; } catch (DataPortalException ex) { this.logger.Log(ex); identity = null; } IsBusy = false; if (identity == null) { await this.messageBox.ShowAsync("There was an error retrieving your profile.", "Error"); } else if (identity.IsAuthenticated) { #if MOBILE Xamarin.Insights.Identify(profileId, Xamarin.Insights.Traits.Name, identity.UserName); Xamarin.Forms.MessagingCenter.Subscribe <VmPageMappings>(this, string.Format(Constants.Navigation.PageNavigated, typeof(PollsPageViewModel)), (sender) => { Xamarin.Forms.MessagingCenter.Unsubscribe <VmPageMappings>(this, string.Format(Constants.Navigation.PageNavigated, typeof(PollsPageViewModel))); //this.Close(this); ChangePresentation(new ClearBackstackHint()); }); #endif // MOBILE // If there is a PollId, the user is coming in from a URI. // Navigate to the Polls page, which adds it to the back stack. // Then, navigate to the View Poll page. This allows the user to be able // to back out of the View Poll page and land on the Polls page, rather than // leaving the app. if (this.NavigationCriteria != null && this.NavigationCriteria.PollId.HasValue) { var criteria = new ViewPollPageNavigationCriteria { PollId = this.NavigationCriteria.PollId.Value }; this.ShowViewModel <PollsPageViewModel>(); #if MOBILE ChangePresentation(new ClearBackstackHint()); #endif this.ShowViewModel <ViewPollPageViewModel>(criteria); #if !MOBILE this.Close(this); #endif } else if (this.NavigationCriteria != null && !string.IsNullOrEmpty(this.NavigationCriteria.SearchQuery)) { var criteria = new PollsPageSearchNavigationCriteria { SearchQuery = this.NavigationCriteria.SearchQuery }; this.ShowViewModel <PollsPageViewModel>(); #if MOBILE ChangePresentation(new ClearBackstackHint()); #endif this.ShowViewModel <ViewPollPageViewModel>(criteria); #if !MOBILE this.Close(this); #endif } else { this.ShowViewModel <PollsPageViewModel>(); #if MOBILE ChangePresentation(new ClearBackstackHint()); #endif #if !MOBILE this.Close(this); #endif } } else { var criteria = new RegistrationPageNavigationCriteria { ProfileId = profileId }; if (this.NavigationCriteria != null) { criteria.PollId = this.NavigationCriteria.PollId; } this.ShowViewModel <RegistrationPageViewModel>(criteria); } }