public bool CreateEmail(Email email)
        {
            using (var context = new CommunicationsContext(_databaseSettings.ConnectionString))
            {
                //create EmailAddresses objects in the context for those that don't yet exist
                //this ensures that the rare case where an email is related to the same address multiple times doesn't fail
                foreach (var emailEmailAddress in email.EmailEmailAddressRelationships)
                {
                    _emailAddressService.CreateEmailAddress(emailEmailAddress.EmailAddress);//will not create duplicates

                }

                //use existing EmailAddresses objects in the context rather than create duplicates
                foreach (var emailEmailAddress in email.EmailEmailAddressRelationships)
                {
                    emailEmailAddress.EmailAddress =
                        context.EmailAddresses.FirstOrDefault(x => x.Email == emailEmailAddress.EmailAddress.Email);
                }

                //don't save those relationships with null (invalid) email addresses
                email.EmailEmailAddressRelationships.RemoveAll(x => x.EmailAddress == null);

                context.Emails.Add(email);

                return context.SaveChanges() > 0;
            }
        }
예제 #2
0
        public bool CreateEmail(Email email, bool isInbound)
        {
            Check.If(email).IsNotNull();
            if (email.IsInvalid())
                return false;

            //set the direction flag based on the caller
            email.IsInbound = isInbound;

            email.GenerateReference(_referenceGenerator);

            return _emailRepository.CreateEmail(email);
        }
        public bool UpdateEmail(string emailReference, Email email)
        {
            using (var context = new CommunicationsContext(_databaseSettings.ConnectionString))
            {
                var currentEmail = context.Emails.FirstOrDefault(x => x.EmailReference == emailReference);

                if (currentEmail == null) return false;

                _emailMapper.Map(email, currentEmail);

                return context.SaveChanges() > 0;
            }
        }
예제 #4
0
 public bool UpdateEmail(string emailReference, Email email)
 {
     Check.If(emailReference).IsNotNullOrEmpty();
     Check.If(email).IsNotNull();
     return _emailRepository.UpdateEmail(emailReference, email);
 }