in FamilyNotes/AppDialogs/AddPersonContentDialog.xaml.cs [140:180]
private async void ContentDialog_PersonName_TextChanged(object sender, TextChangedEventArgs e)
{
// Make sure that our name exists
if (String.IsNullOrWhiteSpace(PersonName.Text))
{
this.IsPrimaryButtonEnabled = false;
textBlock.Text = "Please enter a user name.";
return;
}
// Make sure the name if valid - we can check the directory since each person has a local directory
IStorageItem folderItem = null;
try
{
// See if the folder exists
folderItem = await ApplicationData.Current.LocalFolder.TryGetItemAsync("Users\\" + PersonName.Text);
}
catch (Exception)
{
// We don't get an exception if the item doesn't exist. We will if we were passed an illegal
// path in which case we can't have a user with that name. Or there could be some other
// issue with that directory name. Regardless you can't use that name.
this.IsPrimaryButtonEnabled = false;
textBlock.Text = "Sorry, can't use that name.";
return;
}
// If it doesn't exist, add the user
if (folderItem == null)
{
this.IsPrimaryButtonEnabled = true;
textBlock.Text = "";
}
// If it does, then this user already exists
else
{
this.IsPrimaryButtonEnabled = false;
textBlock.Text = "This user name already exists.";
}
}