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);
			}
		}
示例#2
0
		public void ViewPoll(IPollSearchResult poll)
		{
			if (poll == null)
			{
				throw new ArgumentNullException("poll");
			}

			var criteria = new ViewPollPageNavigationCriteria
			{
				PollId = poll.Id
			};

			this.Navigation.NavigateToViewModel<ViewPollPageViewModel>(criteria);
		}
		public async Task Submit()
		{
			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)
			{
				System.Diagnostics.Debug.WriteLine(ex);
				hasError = true;
			}
			this.IsBusy = false;

			if (!hasError)
			{
				// Always navigate to the Polls page first.
				this.Navigation.NavigateToViewModel<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)
				{
					var criteria = new ViewPollPageNavigationCriteria
					{
						PollId = this.NavigationCriteria.PollId.Value
					};

					this.Navigation.NavigateToViewModel<ViewPollPageViewModel>(criteria);
				}
			}
			else
			{
#if WINDOWS_PHONE
				this.messageBox.Show("There was an error saving your profile. Please try again.", "Error");
#else
				await this.messageBox.ShowAsync("There was an error saving your profile. Please try again.", "Error");
#endif // WINDOWS_PHONE
			}
		}
示例#4
0
        public async Task Submit()
        {
			IsBusy = true;
            var hasError = false;
			try
			{
				if (this.PollImageViewModel.HasImage)
				{
					this.Poll.PollImageLink = await this.PollImageViewModel.UploadImage();
				}

				this.Poll = await this.Poll.SaveAsync() as IPoll;

			}
			catch (DataPortalException ex)
			{
				System.Diagnostics.Debug.WriteLine(ex);
				hasError = true;
			}
			catch (Exception ex)
			{
				System.Diagnostics.Debug.WriteLine(ex);
				hasError = true;
			}
			IsBusy = false;

            if (!hasError)
            {
                if (this.Poll != null && this.Poll.PollID != null)
                {
                    var criteria = new ViewPollPageNavigationCriteria() {PollId = this.Poll.PollID.Value};

					this.Navigation.NavigateToViewModel<ViewPollPageViewModel>(criteria);
                }
            }
            else
            {
#if WINDOWS_PHONE
				this.messageBox.Show("There was an error saving your poll. Please try again.", "Error");
#else
                await this.messageBox.ShowAsync("There was an error saving your poll. Please try again.", "Error");
#endif 
            }
        }
示例#5
0
		private async Task LoadIdentityAndGo(string profileId)
		{
			IUserIdentity identity = null;
			IsBusy = true;
            try
            {
                //identity = (this.objectFactory as IObjectFactory<IUserIdentity>).Fetch(profileId);
                identity = await this.ObjectFactory.FetchAsync(profileId);

                var principal = new CslaPrincipalCore(identity);
                Csla.ApplicationContext.User = principal;
            }
            catch (DataPortalException ex)
            {
                Console.WriteLine(ex.Message);
                identity = null;
                MessageBox.Show(this, ex.Message);
            }

			IsBusy = false;
			if (identity == null)
			{
				this.MessageBox.Show(this, "There was an error retrieving your profile.", "Error");
			}

            else if (identity.IsAuthenticated)
            {
                // 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.Navigation.NavigateToViewModel<PollsPageViewModel>();
                    //this.Navigation.NavigateToViewModel<ViewPollPageViewModel>(criteria);
                }

                else if (this.NavigationCriteria != null && !string.IsNullOrEmpty(this.NavigationCriteria.SearchQuery))
                {
                    var criteria = new PollsPageSearchNavigationCriteria
                    {
                        SearchQuery = this.NavigationCriteria.SearchQuery
                    };

                    //this.Navigation.NavigateToViewModel<PollsPageViewModel>();
                    //this.Navigation.NavigateToViewModel<ViewPollPageViewModel>(criteria);
                }
                else
                {
                    //this.Navigation.NavigateToViewModel<PollsPageViewModel>();
					var polls = new Intent (this, typeof(PollsActivity));
					StartActivity (polls);                
				}
                
            }
            else
            {
                var criteria = new RegistrationPageNavigationCriteria
                {
                    ProfileId = profileId
                };

                if (this.NavigationCriteria != null)
                {
                    criteria.PollId = this.NavigationCriteria.PollId;
                }

				var registration = new Intent (this, typeof(RegistrationActivity));
				registration.PutExtra("NavigationCriteria_PollId", criteria.PollId ?? 0);
				registration.PutExtra ("NavigationCriteria_ProfileId", criteria.ProfileId);
				StartActivity (registration);

                //this.Navigation.NavigateToViewModel<RegistrationPageViewModel>(criteria);
                
            }

		}
示例#6
0
		protected override void OnActivated(IActivatedEventArgs args)
		{
			base.OnActivated(args);

			string serializedCriteria = null;
			if (args != null && args.Kind == ActivationKind.Protocol)
			{
				var protocolArgs = args as ProtocolActivatedEventArgs;
				if (protocolArgs.Uri.Authority.ToLower() == "poll")
				{
					int pollId;
					if (int.TryParse(protocolArgs.Uri.LocalPath.Substring(1), out pollId))
					{
						if (args.PreviousExecutionState == ApplicationExecutionState.Running)
						{
							var criteria = new ViewPollPageNavigationCriteria
							{
								PollId = pollId
							};
							serializedCriteria = Serializer.Serialize(criteria);
						}
						else
						{
							var criteria = new LandingPageNavigationCriteria
							{
								PollId = pollId
							};
							serializedCriteria = Serializer.Serialize(criteria);
						}
					}
				}
			}

			if (args != null && args.PreviousExecutionState == ApplicationExecutionState.Running)
			{
				this.NavigationService.NavigateToViewModel<ViewPollPageViewModel>(serializedCriteria);
			}
			else
			{
				this.DisplayRootView<LandingPage>(serializedCriteria);
			}
		}
示例#7
0
		protected override void OnLaunched(LaunchActivatedEventArgs args)
		{
			string serializedCriteria = null;
			if (!string.IsNullOrEmpty(args.Arguments))
			{
				int pollId;
				if (int.TryParse(args.Arguments, out pollId))
				{
					if (args.PreviousExecutionState == ApplicationExecutionState.Running)
					{
						var criteria = new ViewPollPageNavigationCriteria
						{
							PollId = pollId
						};
						serializedCriteria = Serializer.Serialize(criteria);
					}
					else
					{
						var criteria = new LandingPageNavigationCriteria
						{
							PollId = pollId
						};
						serializedCriteria = Serializer.Serialize(criteria);
					}
				}
			}

			if (args != null && args.PreviousExecutionState == ApplicationExecutionState.Running)
			{
				this.NavigationService.NavigateToViewModel<ViewPollPageViewModel>(serializedCriteria);
			}
			else
			{
				this.DisplayRootView<LandingPage>(serializedCriteria);
			}
		}
示例#8
0
		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)
			{
				Debug.WriteLine(ex.Message);
				identity = null;
			}
			IsBusy = false;

			if (identity == null)
			{
#if WINDOWS_PHONE
				this.messageBox.Show("There was an error retrieving your profile.", "Error");
#else
				await this.messageBox.ShowAsync("There was an error retrieving your profile.", "Error");
#endif // WINDOWS_PHONE
			}
			else if (identity.IsAuthenticated)
			{
				// 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.Navigation.NavigateToViewModel<PollsPageViewModel>();
					this.Navigation.NavigateToViewModel<ViewPollPageViewModel>(criteria);
				}

                else if (this.NavigationCriteria != null && !string.IsNullOrEmpty(this.NavigationCriteria.SearchQuery))
                {
                    var criteria = new PollsPageSearchNavigationCriteria
                    {
                        SearchQuery = this.NavigationCriteria.SearchQuery
                    };

                    this.Navigation.NavigateToViewModel<PollsPageViewModel>();
					this.Navigation.NavigateToViewModel<ViewPollPageViewModel>(criteria);
                }
                else
				{
					this.Navigation.NavigateToViewModel<PollsPageViewModel>();
				}
			}
			else
			{
				var criteria = new RegistrationPageNavigationCriteria
				{
					ProfileId = profileId
				};

				if (this.NavigationCriteria != null)
				{
					criteria.PollId = this.NavigationCriteria.PollId;
				}

				this.Navigation.NavigateToViewModel<RegistrationPageViewModel>(criteria);
			}
		}
示例#9
0
		public async Task Submit()
		{

			this.IsBusy = true;

            var hasError = false;
		    DateTime birthDate;
            hasError = !DateTime.TryParse(FindViewById<Button>(Resource.Id.registration_dob).Text, out birthDate);

		    if (!hasError)
		    {
		        this.User.BirthDate = birthDate;
		        try
		        {
		            Bindings.UpdateSourceForLastView();

		            this.User = await this.User.SaveAsync() as IUser;

		            InitializeBindings(this.User);

		            var identity = await this.UserIdentityObjectFactory.FetchAsync(this.User.ProfileID);

		            var principal = new CslaPrincipalCore(identity);
		            Csla.ApplicationContext.User = principal;
		        }
		        catch (DataPortalException ex)
		        {
		            System.Diagnostics.Debug.WriteLine(ex);
		            hasError = true;
		        }
		    }
		    this.IsBusy = false;

			if (!hasError)
			{

				// Always navigate to Polls page first
				var polls = new Intent (this, typeof(PollsActivity));
				StartActivity (polls);

				// 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)
				{
					var criteria = new ViewPollPageNavigationCriteria
					{
						PollId = this.NavigationCriteria.PollId.Value
					};

					var registration = new Intent (this, typeof(ViewPollFragment));
					registration.PutExtra("PollId", criteria.PollId);
					StartActivity (registration);

					//this.Navigation.NavigateToViewModel<ViewPollPageViewModel>(criteria);
				}

			}
			else
			{
				this.MessageBox.Show(this, "There was an error saving your profile. Please try again.", "Error");
			}

		}
示例#10
0
        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");
            }
        }