public InfosPageViewModel(INavigation navigation) { _nav = navigation; Observable.FromAsync <User>(async() => { var user = await UserManager.Instance.GetUserAsync(); if (user != null && string.IsNullOrEmpty(user?.Token) && string.IsNullOrEmpty(user?.FirstName) || string.IsNullOrEmpty(user?.ZipCode)) { await ServerManager.Instance.GetUserInfosAsync(user?.Token); user = await UserManager.Instance.GetUserAsync(); } return(user); }) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(user => { var start = DateTime.Now; Fullname = "Bonjour " + user?.FirstName + " !"; Departement = "Vous habitez dans le département " + user?.ZipCode?.Substring(0, 2) + "."; var stop = DateTime.Now; Debug.WriteLine("Diff : " + (stop - start).TotalMilliseconds.ToString()); }); LogoutCommand = new Command(async(obj) => { var frame = (Frame)obj; ButtonAnimationHelper.Animate(frame); // -- On delete le user en base await UserManager.Instance.DeleteUserAsync(); Device.BeginInvokeOnMainThread(async() => { await _nav.PopToRootAsync(); }); }); }
//public RgpdPageViewModel(INavigation nav, Reponse reponse) public RgpdPageViewModel(INavigation nav) { _nav = nav; Q1Items = new ObservableCollection <TagViewModel>(); { var f = new TagViewModel { Text = "Oui", Parameters = 1, TextColor = Color.FromHex("#174163"), BackgroundColor = Color.White, }; Q1Items.Add(f); } { var f = new TagViewModel { Text = "Non", Parameters = 1, TextColor = Color.FromHex("#174163"), BackgroundColor = Color.White, }; Q1Items.Add(f); } Q2Items = new ObservableCollection <TagViewModel>(); { var f = new TagViewModel { Text = "Oui", Parameters = 2, TextColor = Color.FromHex("#174163"), BackgroundColor = Color.White, }; Q2Items.Add(f); } { var f = new TagViewModel { Text = "Non", Parameters = 2, TextColor = Color.FromHex("#174163"), BackgroundColor = Color.White, }; Q2Items.Add(f); } Q3Items = new ObservableCollection <TagViewModel>(); { var f = new TagViewModel { Text = "Oui", Parameters = 3, TextColor = Color.FromHex("#174163"), BackgroundColor = Color.White, }; Q3Items.Add(f); } { var f = new TagViewModel { Text = "Non", Parameters = 3, TextColor = Color.FromHex("#174163"), BackgroundColor = Color.White, }; Q3Items.Add(f); } YesNoCommand = new Command(YesNoSelected); ValiderCommand = new Command(async(obj) => { var frame = (Frame)obj; ButtonAnimationHelper.Animate(frame); var emailRegex = @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" + @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$"; if (string.IsNullOrEmpty(Email)) { Email = null; } bool ok = true; if (!string.IsNullOrEmpty(Email)) { ok = (Regex.IsMatch(Email.Trim(), emailRegex, RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250))); } if (_selectedQ2?.Text == "Oui" && string.IsNullOrEmpty(Email)) { ok = false; } if (_selectedQ3?.Text == "Oui" && string.IsNullOrEmpty(Email)) { ok = false; } if (_selectedQ1 != null && _selectedQ2 != null && _selectedQ3 != null && ok) { if (_selectedQ3?.Text == "Oui" && _selectedQ2?.Text != "Oui") { var dialog = DependencyService.Get <IDialogService>(); dialog.Show("Oups !", "Si vous acceptez d'adhérer, vous devez accepter que l'on vous contacte.", "OK", null); } else { SurveyEngineManager.Instance.CurrentReply.Firstname = Prenom; SurveyEngineManager.Instance.CurrentReply.Lastmame = Nom; SurveyEngineManager.Instance.CurrentReply.Email = Email; SurveyEngineManager.Instance.CurrentReply.AgreedToStayInContact = (_selectedQ2?.Text == "Oui" ? true : false); SurveyEngineManager.Instance.CurrentReply.AgreedToContactForJoin = (_selectedQ3?.Text == "Oui" ? true : false); SurveyEngineManager.Instance.CurrentReply.AgreedToTreatPersonalData = (_selectedQ1?.Text == "Oui" ? true : false); await _nav.PushAsync(new MoreInfosPage(new MoreInfosPageViewModel(_nav))); } //await _nav.PushAsync(new EndPage(new EndPageViewModel(_nav))); } else { var dialog = DependencyService.Get <IDialogService>(); dialog.Show("Oups !", "Merci de renseigner toutes les informations sur cet écran.", "OK", null); } }); }