protected void OnContactChanged(ContactViewModel oldContact, ContactViewModel newContact) { if (oldContact?.SharedItems?.ItemCollection != null) { oldContact.SharedItems.ItemCollection.MultiSelectEnabled -= OnMultiSelectEnabled; oldContact.SharedItems.ItemCollection.MultiSelectDisabled -= OnMultiSelectDisabled; oldContact.SharedItems.ItemCollection.AllSelected -= OnAllSelected; } if (newContact == null) { this.CloseEvent?.Invoke(this, EventArgs.Empty); return; } // If achievements is enabled, retrieve achievement data for the new contact if (AccountService.AccountAchievements.IsAchievementsEnabled) { // Only need data from the MAchievementClass.MEGA_ACHIEVEMENT_INVITE type var referralAward = AccountService.AccountAchievements.AwardedClasses.FirstOrDefault( model => model.AchievementClass.HasValue && model.AchievementClass.Value == MAchievementClass.MEGA_ACHIEVEMENT_INVITE); // Find the achievements invite for current contact var referralContact = (ContactViewModel)referralAward?.Contacts.ItemCollection.Items.FirstOrDefault( contact => contact.Handle == newContact.Handle); if (referralContact != null) { // Copy achievement information to the new contact newContact.CopyAchievementDetails(referralContact); } } if (newContact?.SharedItems?.ItemCollection != null) { newContact.SharedItems.ItemCollection.MultiSelectEnabled += OnMultiSelectEnabled; newContact.SharedItems.ItemCollection.MultiSelectDisabled += OnMultiSelectDisabled; newContact.SharedItems.ItemCollection.AllSelected += OnAllSelected; } }