public void LogInOrRegister() { //test wether username field is empty if (Username == null) { MessageBox.Show("Username field can not be empty!"); return; } //test wether Password field is empty if (Password == null) { MessageBox.Show("Password field can not be empty!"); return; } //make sure there are no spaces in the input fields Username = Username.Trim(); Password.Trim(); if (UsersListModel.IsUserInDatabase(Username, Password)) { UsersListModel.SetCurrentUser(Username); windowManager.ShowWindow(new MenuViewModel(windowManager)); return; } if (UsersListModel.IsUsernameInDatabase(Username)) { MessageBox.Show("Username in db"); return; } //if the username does not mathch an existing user, //creates a dialog that asks if the user wants to create an account MessageBoxResult result = MessageBox.Show("Username not found. Do you want to create an account?", "Exit", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { //Create a new account UsersListModel.CurrentUser = new UserModel(Username, Password); UsersListModel.Save(); var currentPath = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory())); //make a new folder for the new user System.IO.Directory.CreateDirectory(currentPath + "/Data/Users/" + Username); windowManager.ShowWindow(new MenuViewModel(windowManager)); return; } return; }
public StatisticsViewModel(IWindowManager windowManager) { _stats = UsersListModel.GetStatistics(); }