private async void TryToLogIn(string userName, string password, bool isLogInButtonPress) { LogInBtn.IsEnabled = false; try { await _viewModel.GetAdministrators(); _viewModel.AdministratorLoggedIn = _viewModel.Administrators.FirstOrDefault(x => x.AdministratorEmail == userName && Decrypt(x.AdministratorPassword) == password); if (_viewModel.AdministratorLoggedIn != null) { Application.Current.Properties.Remove("username"); Application.Current.Properties.Remove("password"); Application.Current.Properties.Add("username", userName); Application.Current.Properties.Add("password", password); await Application.Current.SavePropertiesAsync(); string administratorName = $"{_viewModel.AdministratorLoggedIn.AdministratorFirstName} {_viewModel.AdministratorLoggedIn.AdministratorLastName}"; Analytics.TrackEvent("LoggedIn", new Dictionary <string, string> { { "Administrator", administratorName } }); (Application.Current as App).StartApplication(); return; } else if (isLogInButtonPress) { await DisplayAlert("Error message", "Wrong username or password", "OK"); } } catch (Exception) { await DisplayAlert("Error message", "No connection to server", "OK"); } LoadingView.IsVisible = false; LogInView.IsVisible = true; LogInBtn.IsEnabled = true; }