Example #1
0
        public override EleWise.ELMA.CRM.Models.IContractor Run(Contractor contractor)
        {
            var domain = contractor.Domains.FirstOrDefault()?.DomainString;

            if (string.IsNullOrWhiteSpace(domain))
            {
                throw new ArgumentNullException("domain.DomainString", $"{contractor.Name} пришел с пустым domain");
            }

            var mailboxDomain           = MailboxDomainManager.Instance.Load(domain);
            var mailboxDomainContractor = mailboxDomain?.Contractor;

            if (mailboxDomainContractor == null)
            {
                var settings = Locator.GetServiceNotNull <YambrEmailSettingsModule>().Settings;
                if (settings.AutoCreateContractors)
                {
                    mailboxDomainContractor = EmailMessageParticipantManager.CreateContractor(domain);
                }
            }

            if (mailboxDomainContractor != null)
            {
                UpdateByContractor(mailboxDomainContractor, contractor, domain);
            }


            return(mailboxDomainContractor);
        }
Example #2
0
        public override EleWise.ELMA.CRM.Models.IContact Run(Contact contact)
        {
            var email = contact.Emails.FirstOrDefault()?.EmailString;

            if (string.IsNullOrWhiteSpace(email))
            {
                throw new ArgumentNullException("EmailString", $"{contact.Fio} пришел с пустым email");
            }

            var participant        = EmailMessageParticipantContactManager.Instance.Load(email);
            var contactSummary     = new ContactSummary(email, contact);
            var participantContact = participant?.Contact;

            if (participantContact == null)
            {
                var domain                  = EmailMessageParticipantManager.Domain(email);
                var mailboxDomain           = MailboxDomainManager.Instance.Load(domain);
                var mailboxDomainContractor = mailboxDomain?.Contractor;
                if (mailboxDomainContractor == null)
                {
                    var settings = Locator.GetServiceNotNull <YambrEmailSettingsModule>().Settings;
                    if (settings.AutoCreateContractors)
                    {
                        mailboxDomainContractor = EmailMessageParticipantManager.CreateContractor(domain);
                    }
                }

                participantContact =
                    EmailMessageParticipantManager.CreateContact(
                        contactSummary,
                        mailboxDomainContractor);
                var messageParticipant = EmailMessageParticipantManager.CreateParticipant(contactSummary, participantContact);
                messageParticipant.Save();
            }

            UpdateByContact(participantContact, contact, email);

            return(participantContact);
        }