private async Task DoViewPollAsync() { this.IsBusy = true; var identity = (IUserIdentity)Csla.ApplicationContext.User.Identity; var command = await this.objectFactory.CreateAsync(); command.PollID = this.Id; command.UserID = identity.UserID.HasValue ? identity.UserID.Value : 0; command = await this.objectFactory.ExecuteAsync(command); this.IsBusy = false; if (command.Submission != null) { var criteria = new ViewPollPageNavigationCriteria { PollId = this.Id }; this.ShowViewModel <ViewPollPageViewModel>(criteria); } else { var navigationCriteria = new PollResultsPageNavigationCriteria { PollId = this.Id }; this.ShowViewModel <PollResultsPageViewModel>(navigationCriteria); } }
public async Task SubmitHandlerAsync() { this.IsBusy = true; var hasError = false; try { if (this.PollImageViewModel.HasImage) { this.Poll.PollImageLink = await this.PollImageViewModel.UploadImage().ConfigureAwait(true); } this.Poll = ((IPoll)await this.Poll.SaveAsync()); } catch (DataPortalException ex) { this.logger.Log(ex); hasError = true; } catch (Exception ex) { this.logger.Log(ex); hasError = true; } this.IsBusy = false; if (!hasError) { if (this.Poll != null && this.Poll.PollID != null) { if (PollAdded != null) { PollAdded(this, new AddPollEventArgs { Poll = this.Poll }); } #if !__MOBILE__ this.Close(this); #endif var criteria = new ViewPollPageNavigationCriteria { PollId = this.Poll.PollID.Value }; this.ShowViewModel <ViewPollPageViewModel>(criteria); var viewModelLoader = Mvx.Resolve <IMvxViewModelLoader>(); this.PollImageViewModel = (PollImageViewModel)viewModelLoader.LoadViewModel(new MvxViewModelRequest(typeof(PollImageViewModel), new MvxBundle(), new MvxBundle(), new MvxRequestedBy(MvxRequestedByType.UserAction)), null); this.Start(); } } else { await this.messageBox.ShowAsync("There was an error saving your poll. 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); } }