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(); }
private void EmailAdminsAboutCancellation(string cancellationReason, WebSite.Models.User user) { IEmailFactory emailFactory = System.Web.Mvc.DependencyResolver.Current.GetService(typeof(IEmailFactory)) as IEmailFactory; // Create the email StringBuilder builder = new StringBuilder(); builder.Append("<html><head></head><body><!-- BODY START --><p>A user has cancelled their subscription. <br/> First Name: "); builder.Append(user.FirstName); builder.Append("<br/>Last Name: "); builder.Append(user.LastName); builder.Append("<br/>Email: "); builder.Append(user.EmailAddress); builder.Append("</p><p>Reason: <br/>"); builder.Append(cancellationReason); builder.Append("</p><!-- BODY END --></body></html>"); // Send the email now emailFactory.CreateEmailForAdministrators(builder.ToString(), "Account Cancellation").Send(); }
public override void OnException(ExceptionContext filterContext) { // Email the admins IEmailFactory emailFactory = System.Web.Mvc.DependencyResolver.Current.GetService <IEmailFactory>(); string subject = "Error in website"; StringBuilder body = new StringBuilder(); body.Append("Controller: "); body.Append(filterContext.Controller.ToString()); body.Append("<br/>Raw URL: "); body.Append(filterContext.RequestContext.HttpContext.Request.RawUrl); for (Exception exception = filterContext.Exception; exception != null; exception = exception.InnerException) { this.PrintException(exception, body); } emailFactory.CreateEmailForAdministrators(body.ToString(), subject).Send(); // Do whatever the base class does base.OnException(filterContext); }
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(); }
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(); }