in FamilyNotes/MainPage.xaml.cs [302:349]
private async void AddNewPersonDialog(Person currentPerson)
{
var dialog = new AddPersonContentDialog();
dialog.ProvideExistingPerson(currentPerson);
await dialog.ShowAsync();
Person newPerson = dialog.AddedPerson;
// If there is a valid person to add, add them.
if (newPerson != null)
{
// Get or create a directory for the user (we do this regardless of whether or not there is a profile picture).
StorageFolder userFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(("Users\\" + newPerson.FriendlyName), CreationCollisionOption.OpenIfExists);
// See if we have a profile photo.
if (dialog.TemporaryFile != null)
{
// Save off the profile photo and delete the temporary file.
await dialog.TemporaryFile.CopyAsync(userFolder, "ProfilePhoto.jpg", NameCollisionOption.ReplaceExisting);
await dialog.TemporaryFile.DeleteAsync();
// Update the profile picture for the person.
newPerson.IsProfileImage = true;
newPerson.ImageFileName = userFolder.Path + "\\ProfilePhoto.jpg";
if (AppSettings.FaceApiKey != "")
{
await FacialSimilarity.AddTrainingImageAsync(newPerson.FriendlyName, new Uri($"ms-appdata:///local/Users/{newPerson.FriendlyName}/ProfilePhoto.jpg"));
}
}
// Add the user if it is new now that changes have been made.
if (currentPerson == null)
{
await FamilyModel.AddPersonAsync(newPerson);
}
// Otherwise we had a user, so update the current one.
else
{
//await FamilyModel.UpdatePersonImageAsync(newPerson);
Person personToUpdate = FamilyModel.PersonFromName(currentPerson.FriendlyName);
if (personToUpdate != null)
{
personToUpdate.IsProfileImage = true;
personToUpdate.ImageFileName = userFolder.Path + "\\ProfilePhoto.jpg";
}
}
}
}