private async void SelectLand() { MainViewModel.getInstance().Land = new LandViewModel(this); await App.Navigator.PushAsync(new LandTabbedPage()); //await Application.Current.MainPage.Navigation.PushAsync( new LandTabbedPage() ); }
private IEnumerable <LandItemViewModel> ToLandItemViewModel() { return(MainViewModel.getInstance().LandsList.Select(l => new LandItemViewModel { Alpha2Code = l.Alpha2Code, Alpha3Code = l.Alpha3Code, AltSpellings = l.AltSpellings, Area = l.Area, Borders = l.Borders, CallingCodes = l.CallingCodes, Capital = l.Capital, Cioc = l.Cioc, Currencies = l.Currencies, Demonym = l.Demonym, Flag = l.Flag, Gini = l.Gini, Languages = l.Languages, Latlng = l.Latlng, Name = l.Name, NativeName = l.NativeName, NumericCode = l.NumericCode, Population = l.Population, Region = l.Region, RegionalBlocs = l.RegionalBlocs, Subregion = l.Subregion, Timezones = l.Timezones, TopLevelDomain = l.TopLevelDomain, Translations = l.Translations, })); }
private void Navigate() { //Ocultar MenĂº App.Master.IsPresented = false; if (this.PageName == "LoginPage") { Settings.Token = string.Empty; Settings.TokenType = string.Empty; //-----------Por seguridad... var mainViewModel = MainViewModel.getInstance(); mainViewModel.Token = string.Empty; mainViewModel.TokenType = string.Empty; using (var conn = new SQLite.SQLiteConnection(App.root_db)) { conn.DeleteAll <UserLocal>(); } Application.Current.MainPage = new NavigationPage(new LoginPage()); } else if (this.PageName == "MyProfilePage") { MainViewModel.getInstance().MyProfile = new MyProfileViewModel(); App.Navigator.PushAsync(new MyProfilePage()); } }
public MyProfileViewModel() { this.apiService = new ApiService(); this.User = MainViewModel.getInstance().User; this.ImageSource = this.User.ImageFullPath; this.IsEnabled = true; }
private void LoadBorders() { this.Borders = new ObservableCollection <Border>(); foreach (var border in this.Land.Borders) { var land = MainViewModel.getInstance().LandsList .Where(l => l.Alpha3Code == border).FirstOrDefault(); if (land != null) { this.Borders.Add(new Border { Code = land.Alpha3Code, Name = land.Name }); } } }
private async void LoadLands() { this.IsRefreshing = true; var connection = await this.apiService.CheckConnection(); if (!connection.IsSuccess) { this.IsRefreshing = false; await Application.Current.MainPage.DisplayAlert( "Error", connection.Message, "Accept"); await Application.Current.MainPage.Navigation.PopAsync(); return; } var response = await this.apiService.GetList <Land>( "https://restcountries.eu", "/rest", "/v2/all"); if (!response.IsSuccess) { this.IsRefreshing = false; await Application.Current.MainPage.DisplayAlert( "Error", response.Message, "Accept"); await Application.Current.MainPage.Navigation.PopAsync(); return; } MainViewModel.getInstance().LandsList = (List <Land>)response.Result; this.Lands = new ObservableCollection <LandItemViewModel>(this.ToLandItemViewModel()); this.IsRefreshing = false; }
private async void Login() { if (string.IsNullOrEmpty(this.Email)) { await Application.Current.MainPage.DisplayAlert("Error", "You must enter an email", "Accept"); return; } if (string.IsNullOrEmpty(this.Password)) { await Application.Current.MainPage.DisplayAlert("Error", "You must enter a password", "Accept"); return; } this.IsRunning = true; this.IsEnabled = false; if (this.Email != "*****@*****.**" || this.Password != "1234") { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert("Error", "Email or password incorrect", "Accept"); this.Password = string.Empty; return; } this.IsRunning = false; this.IsEnabled = true; this.Email = string.Empty; this.Password = string.Empty; MainViewModel.getInstance().Lands = new LandsViewModel(); await Application.Current.MainPage.Navigation.PushAsync(new LandsPage()); //await Application.Current.MainPage.DisplayAlert("Ok", "Login correcto", "Accept"); }
private async void Login() { if (String.IsNullOrEmpty(this.Email)) { await Application.Current.MainPage.DisplayAlert(Languages.Error, Languages.EmailValidation, Languages.Accept); return; } if (String.IsNullOrEmpty(this.Password)) { await Application.Current.MainPage.DisplayAlert(Languages.Error, Languages.PasswordValidation, Languages.Accept); return; } this.IsRunning = true; this.IsEnabled = false; var connection = await this.apiService.CheckConnection(); if (!connection.IsSuccess) { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert(Languages.Error, connection.Message, Languages.Accept); return; } var apiSecurity = Application.Current.Resources["APISecurity"].ToString(); var token = await this.apiService.GetToken(apiSecurity, this.Email, this.Password); if (token == null) { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert(Languages.Error, Languages.SomethingWrong, Languages.Accept); return; } if (string.IsNullOrEmpty(token.AccessToken)) { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert(Languages.Error, token.ErrorDescription, Languages.Accept); this.Password = string.Empty; return; } var user = await this.apiService.GetUserByEmail( apiSecurity, "/api", "/Users/GetUserByEmail", this.Email); var userLocal = Converter.ToUserLocal(user); var mainViewModel = MainViewModel.getInstance(); mainViewModel.Token = token.AccessToken; mainViewModel.TokenType = token.TokenType; mainViewModel.User = userLocal; if (this.IsRemember) { //Save LocalUser in SQLite using (var conn = new SQLite.SQLiteConnection(App.root_db)) { conn.CreateTable <UserLocal>(); conn.Insert(userLocal); } //Persistencia Settings.Token = token.AccessToken; Settings.TokenType = token.TokenType; } mainViewModel.Lands = new LandsViewModel(); //await Application.Current.MainPage.Navigation.PushAsync(new LandsPage()); Application.Current.MainPage = new MasterPage(); this.IsRunning = false; this.IsEnabled = true; this.Email = String.Empty; this.Password = String.Empty; }
private async void Register() { MainViewModel.getInstance().Register = new RegisterViewModel(); await Application.Current.MainPage.Navigation.PushAsync(new RegisterPage()); }
private async void Save() { if (string.IsNullOrEmpty(this.User.FirstName)) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.FirstNameValidation, Languages.Accept); return; } if (string.IsNullOrEmpty(this.User.LastName)) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.LastNameValidation, Languages.Accept); return; } if (string.IsNullOrEmpty(this.User.Email)) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.EmailValidation, Languages.Accept); return; } if (!RegexUtilities.IsValidEmail(this.User.Email)) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.EmailValidation2, Languages.Accept); return; } if (string.IsNullOrEmpty(this.User.Telephone)) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.PhoneValidation, Languages.Accept); return; } this.IsRunning = true; this.IsEnabled = false; var checkConnetion = await this.apiService.CheckConnection(); if (!checkConnetion.IsSuccess) { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert( Languages.Error, checkConnetion.Message, Languages.Accept); return; } byte[] imageArray = null; if (this.file != null) { imageArray = FilesHelper.ReadFully(this.file.GetStream()); } var userDomain = Converter.ToUserDomain(this.User, imageArray); var apiSecurity = Application.Current.Resources["APISecurity"].ToString(); var response = await this.apiService.Put( apiSecurity, "/api", "/Users", MainViewModel.getInstance().TokenType, MainViewModel.getInstance().Token, userDomain); if (!response.IsSuccess) { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert( Languages.Error, response.Message, Languages.Accept); return; } this.IsRunning = false; this.IsEnabled = true; await App.Navigator.PopAsync(); }