public string InsertOrUpdateContact(IContactInfo contact) { string result = contact.Key; lock (_contacts) { var target = _contacts.FirstOrDefault(x => x.Key == contact.Key); if (target == null) { target = ContactInfo.GetLocalObject(contact); target.Key = Guid.NewGuid().ToString("D"); result = target.Key; _contacts.Add(target); } else { _contacts.Remove(target); _contacts.Add(ContactInfo.GetLocalObject(contact)); } } FlushDb(); return(result); }