private async void b_register_Click(object sender, RoutedEventArgs e) { if (Role == "Fan") { var metroWindow = (Application.Current.MainWindow as MetroWindow); await metroWindow.ShowMessageAsync("Register Failed", "The Fan functionality is not yet available. We'll message when it is", MessageDialogStyle.Affirmative); return; } // Create a new user and generate data. UserGenerator newUser = new UserGenerator(tb_username.Text, pb_password.Password, Role); newUser.generate(); // Read from user DB and add new user to the db string dir = Directory.GetCurrentDirectory() + "\\Data\\users.json"; List <UserTemplate> allUsers; using (var streamReader = new StreamReader(dir)) using (JsonReader reader = new JsonTextReader(streamReader)) { JsonSerializer serializer = new JsonSerializer(); allUsers = serializer.Deserialize <List <UserTemplate> >(reader); } allUsers.Add(newUser.getUser()); string json = JsonConvert.SerializeObject(allUsers, Formatting.Indented); // Write to resource and to file on PC, ON RELEASE DELETE SYSTEM.IO LINE using (var streamWriter = new StreamWriter(dir)) { streamWriter.Write(json); } System.IO.File.WriteAllText(System.AppDomain.CurrentDomain.BaseDirectory + "../../Data/users.json", json); //Redirect var mainWindow = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault(); mainWindow.hideBackButton(); NavigationService.GoBack(); NavigationService.GoBack(); if (Role == "Player") { PlayerWindow n_window = new PlayerWindow(newUser.getUser()); n_window.Show(); } mainWindow.Hide(); }