예제 #1
0
 private void ExpectFactoryCalls(int repeatCount)
 {
     Expect.Call(_emailFactory.CreateEmail(null)).IgnoreArguments()
     .Return(new Email(string.Empty, string.Empty)).Repeat.Times(2 * repeatCount);
     Expect.Call(_phoneNumberFactory.CreatePhoneNumber(null, 0)).IgnoreArguments()
     .Return(new PhoneNumber(null, null, 0)).Repeat.Times(3 * repeatCount);
     Expect.Call(_userLoginFactory.CreateUserLogin(null)).IgnoreArguments()
     .Return(new UserLogin(0)).Repeat.Times(repeatCount);
 }
예제 #2
0
        public override void Execute(Quartz.IJobExecutionContext context)
        {
            if (context.ScheduledFireTimeUtc.HasValue)
            {
                DateTimeOffset scheduledTime   = context.ScheduledFireTimeUtc.Value;
                DateTime       easternDateTime = TimeZoneInfo.ConvertTimeFromUtc(scheduledTime.UtcDateTime, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));

                // If it's the weekend, don't send email
                if (easternDateTime.DayOfWeek == DayOfWeek.Sunday || easternDateTime.DayOfWeek == DayOfWeek.Saturday)
                {
                    return;
                }

                // Is today a stock market holiday?
                if (this.IsStockMarketHoliday(easternDateTime))
                {
                    return;
                }
            }

            IEnumerable <IUser> usersWithActiveSubscription = _database.GetActiveUsersWantingToReceiveAlerts;

            // Get the email
            IEmail morningMarketAlertEmail = _emailFactory.CreateEmail(
                contents: this.GetEmailContents(),
                subject: "Market Alert",
                // recipients: new List<IEmailRecipient>() { new EmailRecipient() { Name = "Mohammad Mohammadi", EmailAddress = "*****@*****.**" },
                // new EmailRecipient() { Name = "Mehdi Ghaffari", EmailAddress = "*****@*****.**" },
                // new EmailRecipient() { Name = "Ameen Tayyebi", EmailAddress = "*****@*****.**" } });
                recipients: usersWithActiveSubscription);

            morningMarketAlertEmail.Send();
        }
예제 #3
0
 public Host CreateHost(ProspectsEntity prospectsEntity, Address address, Address mailingAddress)
 {
     return(new Host(prospectsEntity.ProspectId)
     {
         Address = address,
         MailingAddress = mailingAddress,
         OrganizationName = prospectsEntity.OrganizationName ?? string.Empty,
         TaxIdNumber = prospectsEntity.TaxIdNumber ?? string.Empty,
         Notes = prospectsEntity.Notes,
         Email = _emailFactory.CreateEmail(prospectsEntity.EmailId),
         OfficePhoneNumber =
             _phoneNumberFactory.CreatePhoneNumber(prospectsEntity.PhoneOffice, PhoneNumberType.Office),
         MobilePhoneNumber =
             _phoneNumberFactory.CreatePhoneNumber(prospectsEntity.PhoneCell, PhoneNumberType.Mobile),
         OtherPhoneNumber =
             _phoneNumberFactory.CreatePhoneNumber(prospectsEntity.PhoneOther, PhoneNumberType.Unknown),
         Status =
             HostStatus.HostStatuses.Find(
                 hostStatus => hostStatus.PersistenceLayerId.ToString() == prospectsEntity.Status),
         Type = prospectsEntity.ProspectTypeId.HasValue ? ((HostProspectType)prospectsEntity.ProspectTypeId.Value) : HostProspectType.Other,
         FaxNumber = _phoneNumberFactory.CreatePhoneNumber(prospectsEntity.Fax, PhoneNumberType.Unknown),
         DataRecorderMetaData = new DataRecorderMetaData
         {
             DateCreated = prospectsEntity.DateCreated,
             DateModified = prospectsEntity.DateModified,
             DataRecorderCreator = prospectsEntity.OrgRoleUserId.HasValue ? new OrganizationRoleUser(prospectsEntity.OrgRoleUserId.Value) : null
         },
         IsHost = prospectsEntity.IsHost.HasValue && prospectsEntity.IsHost.Value
     });
 }
예제 #4
0
        public override void Execute(IJobExecutionContext context)
        {
            // Get the list of users who have an active trial and have not logged in for more than 5 days
            List <IUser> inactiveUsers = (from user in _database.GetUsers
                                          where !user.SubscriptionId.HasValue && user.TrialExpiryDate > DateTime.UtcNow &&
                                          EntityFunctions.DiffDays(user.LastLoginDate, DateTime.UtcNow) >= 5 &&
                                          !user.SentInactiveReminder
                                          select user).ToList();

            // Generate email for inactive members
            // TODO: EmailResult emailContents = _accountEmailFactory.InactiveTrialAccount();
            IEmail inactiveUserEmail = _emailFactory.CreateEmail(
                contents: this.GetEmailContents(),
                subject: "Inactive Trial Account",
                recipients: inactiveUsers);

            // Send the email to users
            inactiveUserEmail.Send();

            // Mark the users so that they don't get duplicate notifications
            foreach (var user in inactiveUsers)
            {
                user.SentInactiveReminder = true;
            }
            _database.SaveChanges();

            // Notify dear admins
            StringBuilder adminEmailContents = new StringBuilder();

            adminEmailContents.Append("<html><head></head><body>Fellow admins, your server over here speaking. I just reminded ");
            adminEmailContents.Append(inactiveUsers.Count);
            adminEmailContents.Append(" users that they have been inactive for more than 5 days. Here is who I sent email to:<br/><br/>");

            foreach (IUser user in inactiveUsers)
            {
                adminEmailContents.Append(user.FirstName);
                adminEmailContents.Append(" ");
                adminEmailContents.Append(user.LastName);
                adminEmailContents.Append(" ");
                adminEmailContents.Append(user.EmailAddress);
                adminEmailContents.Append("<br/>");
            }

            adminEmailContents.Append("I'm going to go sleep for another day now.</body></html>");

            IEmail adminNotificationEmail = _emailFactory.CreateEmailForAdministrators(adminEmailContents.ToString(), "Inactive Users Report " + DateTime.UtcNow.ToShortDateString());

            adminNotificationEmail.Send();
        }
예제 #5
0
 public Contact CreateContact(ContactsEntity contactsEntity)
 {
     return(new Contact(contactsEntity.ContactId)
     {
         Name = new Name(contactsEntity.FirstName, contactsEntity.MiddleName, contactsEntity.LastName),
         Email = _emailFactory.CreateEmail(contactsEntity.Email),
         HomePhoneNumber =
             _phoneNumberFactory.CreatePhoneNumber(contactsEntity.PhoneHome, PhoneNumberType.Home),
         MobilePhoneNumber =
             _phoneNumberFactory.CreatePhoneNumber(contactsEntity.PhoneCell, PhoneNumberType.Mobile),
         OfficePhoneNumber =
             _phoneNumberFactory.CreatePhoneNumber(contactsEntity.PhoneOffice, PhoneNumberType.Office),
         OfficePhoneExtn = contactsEntity.PhoneOfficeExtension
     });
 }
예제 #6
0
        protected override void MapDomainFields(ProspectCustomerEntity entity, ProspectCustomer domainObjectToMapTo)
        {
            domainObjectToMapTo.Id      = entity.ProspectCustomerId;
            domainObjectToMapTo.Address = new Address
            {
                City  = entity.City,
                State = entity.State,
                StreetAddressLine1 = entity.Address1,
                StreetAddressLine2 = entity.Address2,
                ZipCode            = new ZipCode {
                    Zip = entity.ZipCode
                }
            };
            domainObjectToMapTo.BirthDate       = entity.Dob;
            domainObjectToMapTo.Email           = _emailFactory.CreateEmail(entity.Email);
            domainObjectToMapTo.FirstName       = entity.FirstName;
            domainObjectToMapTo.LastName        = entity.LastName;
            domainObjectToMapTo.MarketingSource = entity.MarketingSource;
            domainObjectToMapTo.PhoneNumber     = _phoneNumberFactory.CreatePhoneNumber(entity.IncomingPhoneLine,
                                                                                        PhoneNumberType.Unknown);
            domainObjectToMapTo.CallBackPhoneNumber = _phoneNumberFactory.CreatePhoneNumber(entity.CallbackNo,
                                                                                            PhoneNumberType.Unknown);
            domainObjectToMapTo.SourceCodeId = entity.SourceCodeId;
            domainObjectToMapTo.Gender       = !string.IsNullOrEmpty(entity.Gender)
                                             ? (Gender)Enum.Parse(typeof(Gender), entity.Gender, true)
                                             : Gender.Unspecified;
            domainObjectToMapTo.Source = (ProspectCustomerSource)entity.Source;
            domainObjectToMapTo.Tag    = !string.IsNullOrEmpty(entity.Tag)
                                          ? (ProspectCustomerTag)
                                         Enum.Parse(typeof(ProspectCustomerTag), entity.Tag, true)
                                          : ProspectCustomerTag.Unspecified;

            domainObjectToMapTo.IsConverted           = entity.IsConverted;
            domainObjectToMapTo.CustomerId            = entity.CustomerId;
            domainObjectToMapTo.ConvertedOnDate       = entity.DateConverted;
            domainObjectToMapTo.CreatedOn             = entity.DateCreated;
            domainObjectToMapTo.IsContacted           = entity.IsContacted;
            domainObjectToMapTo.ContactedDate         = entity.ContactedDate;
            domainObjectToMapTo.ContactedBy           = entity.ContactedBy;
            domainObjectToMapTo.Status                = entity.Status;
            domainObjectToMapTo.CallBackRequestedOn   = entity.CallBackRequestedOn;
            domainObjectToMapTo.CallBackRequestedDate = entity.CallBackRequestedDate;
            domainObjectToMapTo.CallBackRequestedDate = entity.CallBackRequestedDate;
            domainObjectToMapTo.IsQueuedForCallBack   = entity.IsQueuedForCallBack;
            domainObjectToMapTo.TagUpdateDate         = entity.TagUpdateDate;
        }
예제 #7
0
        public static void SendEmail(EmailResult email, IEnumerable<IEmailRecipient> recipients, bool sendToAutoTrading = false)
        {
            IEmailFactory emailFactory = System.Web.Mvc.DependencyResolver.Current.GetService(typeof(IEmailFactory)) as IEmailFactory;

            string body = string.Empty;

            if (!string.IsNullOrEmpty(email.Mail.Body))
            {
                body = email.Mail.Body;
            }
            else
            {
                // Do we have any alternate views that we could use?
                if (email.Mail.AlternateViews.Count > 0)
                {
                    using (var reader = new StreamReader(email.Mail.AlternateViews[0].ContentStream))
                    {
                        body = reader.ReadToEnd();
                    }
                }
            }

            if (sendToAutoTrading)
            {
                List<IEmailRecipient> recipientsWithAutoTrading = new List<IEmailRecipient>(recipients);

                // Add E-option's email address so that they get the email and can place trades in reaction to it
                recipientsWithAutoTrading.Add(new EmailRecipient() { Name = "E-Option", EmailAddress = "*****@*****.**" });

                // Do the same with Global Auto Trading
                recipientsWithAutoTrading.Add(new EmailRecipient() { Name = "Global Auto Trading", EmailAddress = "*****@*****.**" });

                // And for AutoShares
                recipientsWithAutoTrading.Add(new EmailRecipient() { Name = "AutoShares.com", EmailAddress = "*****@*****.**" });
                recipientsWithAutoTrading.Add(new EmailRecipient() { Name = "AutoShares.com", EmailAddress = "*****@*****.**" });

                recipients = recipientsWithAutoTrading;
            }

            emailFactory.CreateEmail(body, email.Mail.Subject, recipients).Send();
        }
예제 #8
0
        public override void Execute(IJobExecutionContext context)
        {
            // Check today's time and find all users whose trial expiry is today
            // Look up all users whose trial expires today
            List <IUser> usersWithSuspendedPayment = _database.GetUsersWithSuspendedPayments.ToList();

            // Get the email
            IEmail paymentSuspendedEmail = _emailFactory.CreateEmail(
                contents: this.GetEmailContents(),
                subject: "Subscription Suspended",
                recipients: usersWithSuspendedPayment);

            // Finally send the email
            paymentSuspendedEmail.Send();

            // Now let the admins know about the email sent
            IEmail adminNotificationEmail = _emailFactory.CreateEmailForAdministrators(
                this.GenerateAdminNotificationEmail(usersWithSuspendedPayment),
                "Users With Suspended Payment Report " + DateTime.UtcNow.ToShortDateString());

            adminNotificationEmail.Send();
        }
예제 #9
0
        public override void Execute(IJobExecutionContext context)
        {
            // Check today's time and find all users whose trial expiry is today
            // Look up all users whose trial expires today
            List <IUser> usersWithExpiredTrial = (from user in _database.GetUsers
                                                  where !user.SubscriptionId.HasValue &&
                                                  EntityFunctions.DiffDays(user.TrialExpiryDate, EntityFunctions.CreateDateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 0, 0, 0)) == 0 &&
                                                  !user.SentTrialExpiryEmail
                                                  select user).ToList();

            // Generate the email contents
            // TODO
            // EmailResult trialExpiredEmailContents = _accountEmailFactory.TrialExpired();

            // Get the email
            IEmail trialExpiredEmail = _emailFactory.CreateEmail(
                contents: this.GetEmailContents(),
                subject: "Trial Membership Conclusion",
                recipients: usersWithExpiredTrial);

            // Finally send the email
            trialExpiredEmail.Send();

            // Mark that we have sent the email to the users
            foreach (var user in usersWithExpiredTrial)
            {
                user.SentTrialExpiryEmail = true;
            }
            _database.SaveChanges();

            // Now let the admins know about the email sent
            IEmail adminNotificationEmail = _emailFactory.CreateEmailForAdministrators(
                this.GenerateAdminNotificationEmail(usersWithExpiredTrial),
                "Users With Expired Trial Report " + DateTime.UtcNow.ToShortDateString());

            adminNotificationEmail.Send();
        }
예제 #10
0
 public void CreateEmailThrowsExceptionWhenGivenNullString()
 {
     _emailFactory.CreateEmail(null);
 }