Exemple #1
0
        public void RemoveContacts(List <int> ids)
        {
            if (!ids.Any())
            {
                throw new ArgumentNullException("ids");
            }

            using (var daoFactory = new DaoFactory())
            {
                using (var tx = daoFactory.DbManager.BeginTransaction())
                {
                    var daoContact = daoFactory.CreateContactDao(Tenant, User);

                    daoContact.RemoveContacts(ids);

                    var daoContactInfo = daoFactory.CreateContactInfoDao(Tenant, User);

                    daoContactInfo.RemoveByContactIds(ids);

                    tx.Commit();
                }
            }

            var factory = new EngineFactory(Tenant, User, Log);

            Log.Debug("IndexEngine->RemoveContacts()");

            factory.IndexEngine.RemoveContacts(ids, Tenant, new Guid(User));
        }
Exemple #2
0
        public ContactCard SaveContactCard(ContactCard contactCard)
        {
            using (var daoFactory = new DaoFactory())
            {
                using (var tx = daoFactory.DbManager.BeginTransaction(IsolationLevel.ReadUncommitted))
                {
                    var daoContact     = daoFactory.CreateContactDao(Tenant, User);
                    var daoContactInfo = daoFactory.CreateContactInfoDao(Tenant, User);

                    var contactId = daoContact.SaveContact(contactCard.ContactInfo);

                    contactCard.ContactInfo.Id = contactId;

                    foreach (var contactItem in contactCard.ContactItems)
                    {
                        contactItem.ContactId = contactId;

                        var contactItemId = daoContactInfo.SaveContactInfo(contactItem);

                        contactItem.Id = contactItemId;
                    }

                    tx.Commit();
                }
            }

            var factory = new EngineFactory(Tenant, User, Log);

            Log.Debug("IndexEngine->SaveContactCard()");

            factory.IndexEngine.Add(contactCard.ToMailContactWrapper());

            return(contactCard);
        }
Exemple #3
0
        public ContactCard UpdateContactCard(ContactCard newContactCard)
        {
            var contactId = newContactCard.ContactInfo.Id;

            if (contactId < 0)
            {
                throw new ArgumentException("Invalid contact id");
            }

            var contactCard = GetContactCard(contactId);

            if (null == contactCard)
            {
                throw new ArgumentException("Contact not found");
            }

            var contactChanged = !contactCard.ContactInfo.Equals(newContactCard.ContactInfo);

            var newContactItems = newContactCard.ContactItems.Where(c => !contactCard.ContactItems.Contains(c)).ToList();

            var removedContactItems = contactCard.ContactItems.Where(c => !newContactCard.ContactItems.Contains(c)).ToList();

            if (!contactChanged && !newContactItems.Any() && !removedContactItems.Any())
            {
                return(contactCard);
            }

            using (var daoFactory = new DaoFactory())
            {
                using (var tx = daoFactory.DbManager.BeginTransaction(IsolationLevel.ReadUncommitted))
                {
                    if (contactChanged)
                    {
                        var daoContact = daoFactory.CreateContactDao(Tenant, User);

                        daoContact.SaveContact(newContactCard.ContactInfo);

                        contactCard.ContactInfo = newContactCard.ContactInfo;
                    }

                    var daoContactInfo = daoFactory.CreateContactInfoDao(Tenant, User);

                    if (newContactItems.Any())
                    {
                        foreach (var contactItem in newContactItems)
                        {
                            contactItem.ContactId = contactId;

                            var contactItemId = daoContactInfo.SaveContactInfo(contactItem);

                            contactItem.Id = contactItemId;

                            contactCard.ContactItems.Add(contactItem);
                        }
                    }

                    if (removedContactItems.Any())
                    {
                        foreach (var contactItem in removedContactItems)
                        {
                            daoContactInfo.RemoveContactInfo(contactItem.Id);

                            contactCard.ContactItems.Remove(contactItem);
                        }
                    }

                    tx.Commit();
                }
            }

            var factory = new EngineFactory(Tenant, User, Log);

            Log.Debug("IndexEngine->UpdateContactCard()");

            factory.IndexEngine.Update(new List <MailContactWrapper> {
                contactCard.ToMailContactWrapper()
            });

            return(contactCard);
        }