// .........................................................................Setup Removed Collaborator..................................................................... private async Task SetupRemovedCollaborator(NicheShackContext context, object state) { EmailSetupParams emailSetupParams = (EmailSetupParams)state; // Get the customer id string customerId = await context.ListCollaborators .AsNoTracking() .Where(x => x.Id == emailSetupParams.CollaboratorId && x.Customer.EmailPrefRemovedCollaborator == true) .Select(x => x.CustomerId) .SingleOrDefaultAsync(); if (customerId == null) { return; } // Get the recipient var recipient = await context.Customers .AsNoTracking() .Where(x => x.Id == customerId) .Select(x => new { firstName = x.FirstName, lastName = x.LastName, email = x.Email }).SingleAsync(); // Get the list string list = await context.Lists .AsNoTracking() .Where(x => x.Id == emailSetupParams.ListId1) .Select(x => x.Name).SingleAsync(); // Add email to queue emailService.AddToQueue(EmailType.RemovedCollaborator, "Removed from list", new Recipient { Email = recipient.email, FirstName = recipient.firstName, LastName = recipient.lastName }, new EmailProperties { Host = emailSetupParams.Host, Var1 = list }); }
// .........................................................................Setup Added List Item Email..................................................................... private async Task SetupAddedListItemEmail(NicheShackContext context, object state) { EmailSetupParams emailSetupParams = (EmailSetupParams)state; List <string> recipientIds = await GetRecipientIds(context, EmailType.AddedListItem, emailSetupParams.ListId1, emailSetupParams.CustomerId); EmailParams emailParams = await GetEmailParams(context, emailSetupParams.CustomerId, emailSetupParams.ListId1, emailSetupParams.Host, recipientIds, emailSetupParams.ProductId); if (emailParams == null) { return; } // Add emails to the queue SubmitAddedListItemEmailsToQueue(emailParams); }
// .........................................................................Setup Email..................................................................... private async Task SetupEmail(NicheShackContext context, object state) { EmailSetupParams emailSetupParams = (EmailSetupParams)state; Recipient recipient = await context.Customers .AsNoTracking() .Where(x => x.Id == emailSetupParams.CustomerId && x.EmailPrefReview == true) .Select(x => new Recipient { FirstName = x.FirstName, LastName = x.LastName, Email = x.Email }) .SingleOrDefaultAsync(); if (recipient == null) { return; } ProductData product = await context.Products .AsNoTracking() .Where(x => x.Id == emailSetupParams.ProductId) .Select(x => new ProductData { Name = x.Name, Image = x.Media.Url, Url = emailSetupParams.Host + "/" + x.UrlName + "/" + x.UrlId }).SingleAsync(); emailService.AddToQueue(EmailType.Review, "Thank you for reviewing " + product.Name + " on Niche Shack", recipient, new EmailProperties { Host = emailSetupParams.Host, Product = product, Stars = await GetStarsImage(emailSetupParams.ProductRating, context), Var1 = emailSetupParams.Title, Var2 = emailSetupParams.Text }); }
// .........................................................................Setup Added Collaborator Email..................................................................... private async Task SetupAddedCollaboratorEmail(NicheShackContext context, object state) { EmailSetupParams emailSetupParams = (EmailSetupParams)state; List <string> recipientIds = await GetRecipientIds(context, EmailType.NewCollaborator, emailSetupParams.ListId1, emailSetupParams.CustomerId); EmailParams emailParams = await GetEmailParams(context, emailSetupParams.CustomerId, emailSetupParams.ListId1, emailSetupParams.Host, recipientIds); if (emailParams == null) { return; } emailService.AddToQueue(EmailType.NewCollaborator, "A new Collaborator has joined your list", emailParams.Recipients, new EmailProperties { Host = emailParams.Host, Link = emailParams.Host + "/account/lists/" + emailParams.List.Id, Person = emailParams.Collaborator, Var1 = emailParams.List.Name }); }
// .........................................................................Setup Changed List Name..................................................................... private async Task SetupChangedListName(NicheShackContext context, object state) { EmailSetupParams emailSetupParams = (EmailSetupParams)state; List <string> recipientIds = await GetRecipientIds(context, EmailType.ListNameChange, emailSetupParams.ListId1, emailSetupParams.CustomerId); EmailParams emailParams = await GetEmailParams(context, emailSetupParams.CustomerId, emailSetupParams.ListId1, emailSetupParams.Host, recipientIds); if (emailParams == null) { return; } // Add email to queue emailService.AddToQueue(EmailType.ListNameChange, "List name changed", emailParams.Recipients, new EmailProperties { Host = emailSetupParams.Host, Var1 = emailSetupParams.Var1, Var2 = emailSetupParams.Var2, Person = emailParams.Collaborator }); }
// .........................................................................Send Moved List Item Email..................................................................... private async Task SetupMovedListItemEmail(NicheShackContext context, object state) { EmailSetupParams emailSetupParams = (EmailSetupParams)state; List <string> fromListCustomerIds = await context.ListCollaborators .AsNoTracking() .Where(x => x.ListId == emailSetupParams.ListId1 && !x.IsRemoved && x.CustomerId != emailSetupParams.CustomerId && x.Customer.EmailPrefMovedListItem == true) .Select(x => x.CustomerId) .ToListAsync(); List <string> bothListRecipientIds = await context.ListCollaborators .AsNoTracking() .Where(x => x.ListId == emailSetupParams.ListId2 && !x.IsRemoved && x.CustomerId != emailSetupParams.CustomerId && fromListCustomerIds.Contains(x.CustomerId) && x.Customer.EmailPrefMovedListItem == true) .Select(x => x.CustomerId) .ToListAsync(); if (bothListRecipientIds.Count > 0) { EmailParams bothListEmailParams = await GetEmailParams(context, emailSetupParams.CustomerId, emailSetupParams.ListId2, emailSetupParams.Host, bothListRecipientIds, emailSetupParams.ProductId); string fromListName = await context.Lists .AsNoTracking() .Where(x => x.Id == emailSetupParams.ListId1) .Select(x => x.Name) .SingleAsync(); emailService.AddToQueue(EmailType.MovedListItem, "An item has been moved to another list", bothListEmailParams.Recipients, new EmailProperties { Host = bothListEmailParams.Host, Product = bothListEmailParams.Product, Link = bothListEmailParams.Host + "/account/lists/" + bothListEmailParams.List.Id, Person = bothListEmailParams.Collaborator, Var1 = fromListName, Var2 = bothListEmailParams.List.Name }); } List <string> fromListRecipientIds = await GetRecipientIds(context, EmailType.RemovedListItem, emailSetupParams.ListId1, emailSetupParams.CustomerId); fromListRecipientIds = fromListRecipientIds.Where(x => !bothListRecipientIds.Contains(x)).ToList(); if (fromListRecipientIds.Count > 0) { EmailParams fromListEmailParams = await GetEmailParams(context, emailSetupParams.CustomerId, emailSetupParams.ListId1, emailSetupParams.Host, fromListRecipientIds, emailSetupParams.ProductId); SubmitRemovedListItemEmailsToQueue(fromListEmailParams); } List <string> toListRecipientIds = await GetRecipientIds(context, EmailType.AddedListItem, emailSetupParams.ListId2, emailSetupParams.CustomerId); toListRecipientIds = toListRecipientIds.Where(x => !bothListRecipientIds.Contains(x)).ToList(); if (toListRecipientIds.Count > 0) { EmailParams toListEmailParams = await GetEmailParams(context, emailSetupParams.CustomerId, emailSetupParams.ListId2, emailSetupParams.Host, toListRecipientIds, emailSetupParams.ProductId); SubmitAddedListItemEmailsToQueue(toListEmailParams); } }