public void AssignAccount(string account, EAccountType accountType, PersonInfo person) { lock (_lockObj) { Debug.Assert(person != null); // create a new account Debug.Assert(!IsKnownAccount(account, accountType)); int accountId = SQLAddNewAccount(account, (int)accountType, person.PersonId, person.Name); string accountKey = GetAccountKey(account, accountType); _accountToAccountId[accountKey] = accountId; _accountIdToAccount[accountId] = accountKey; _accountIdToPersonName[accountId] = person.Name; person.AddAccount(accountId); _accountIdToPersonId[accountId] = person.PersonId; // use the same id as was set for the first email of the person SQLSetPersonId(accountId, person.PersonId); } }
public void ReassignAccountToExistingAccount(int accountId, PersonInfo fromPerson, PersonInfo toPerson) { Debug.Assert(fromPerson != null); Debug.Assert(toPerson != null); if (fromPerson.PersonId == toPerson.PersonId) return; lock (_lockObj) { fromPerson.RemoveAccount(accountId); toPerson.AddAccount(accountId); _accountIdToPersonId[accountId] = toPerson.PersonId; SQLSetPersonId(accountId, toPerson.PersonId); // update person info based on account type EAccountType accountType = GetAccountType(accountId); // if the fromPerson has no more email contacts then we remove the reference to the fromPerson bool noMoreAccounts = (fromPerson.GetAccountIds().Count() == 0); if (noMoreAccounts) { _personIdToPerson.Remove(fromPerson.PersonId); SQLRemovePerson(fromPerson.PersonId); } } }