Пример #1
0
        public static ContactInfo Convert(FoundOps.Core.Models.CoreEntities.ContactInfo contactInfoModel)
        {
            var contactInfo = new ContactInfo
                {
                    Id = contactInfoModel.Id,
                    CreatedDate = contactInfoModel.CreatedDate,
                    Type = contactInfoModel.Type,
                    Label = contactInfoModel.Label,
                    Data = contactInfoModel.Data,
                    ClientId = contactInfoModel.ClientId,
                    LocationId = contactInfoModel.LocationId
                };

            contactInfo.SetLastModified(contactInfoModel.LastModified, contactInfoModel.LastModifyingUserId);

            //TODO Generalize this everywhere
            if (string.IsNullOrEmpty(contactInfo.Type))
                contactInfo.Type = "";
            if (string.IsNullOrEmpty(contactInfo.Label))
                contactInfo.Label = "";
            if (string.IsNullOrEmpty(contactInfo.Data))
                contactInfo.Data = "";

            return contactInfo;
        }
Пример #2
0
        /// <summary>
        /// Try to match the imported ContactInfo to one previously saved
        /// If found, add the it to the ContactInfo dictionary to be imported
        /// Else, create a new ContactInfo and add it to both the ContactInfo dictionary to be imported and the list of ContactInfo to be searched on the next attempt to match
        /// </summary>
        /// <param name="labelDictionary">Dictionary of the ContactInfo labels</param>
        /// <param name="valueDictionary">Dictionary of the ContactInfo values</param>
        /// <param name="index">The index at which to look in the label/value dictionaries</param>
        /// <param name="contactInfoDictionary">Contact information to be imported</param>
        /// <param name="type">The type of ContactInfo the is being imported</param>
        private void MatchContactInfo(Dictionary<int, string> labelDictionary, Dictionary<int, string> valueDictionary, long index, ConcurrentDictionary<Guid, ContactInfo> contactInfoDictionary, string type)
        {
            //Find the label and data for the ContactInfo being imported
            var label = labelDictionary.Any() ? labelDictionary.First(p => p.Key == index).Value.Trim() : null;
            var data = valueDictionary.Any() ? valueDictionary.First(p => p.Key == index).Value.Trim() : null;

            //Try to find existing ContactInfo
            var existingContact = _contactInfoSets.FirstOrDefault(ci => ci.Value.Label == label && ci.Value.Data == data);

            if (existingContact.Key != Guid.Empty)
            {
                //Convert the ContactInfo and add a linked status to it
                var existingContactInfo = ContactInfo.Convert(existingContact.Value);
                existingContactInfo.StatusInt = (int)ImportStatus.Linked;

                contactInfoDictionary.GetOrAdd(existingContact.Value.Id, existingContactInfo);
            }
            else
            {
                var newContactInfo = new ContactInfo
                    {
                        Id = Guid.NewGuid(),
                        Data = data,
                        Label = label,
                        Type = type,
                        StatusInt = (int)ImportStatus.New
                    };

                //Add the new contact info to the list being imported
                contactInfoDictionary.GetOrAdd(newContactInfo.Id, newContactInfo);

                //Since the contact info is new, we add it to the contact info set to be searched next time we try and match
                _contactInfoSets.GetOrAdd(newContactInfo.Id, ContactInfo.ConvertBack(newContactInfo));
            }
        }