// .........................................................................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
            });
        }
Exemple #2
0
        public async Task <ActionResult> UpdateCustomerName(UpdatedCustomerName updatedCustomerName)
        {
            // Get the customer from the database based on the customer id from the claims via the access token
            Customer customer = await userManager.FindByIdAsync(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            // If the customer is found, update his/her name
            if (customer != null)
            {
                customer.FirstName = updatedCustomerName.FirstName;
                customer.LastName  = updatedCustomerName.LastName;

                // Update the name in the database
                IdentityResult result = await userManager.UpdateAsync(customer);

                if (result.Succeeded)
                {
                    // Send a confirmation email that the customer name has been changed
                    if (customer.EmailPrefNameChange == true)
                    {
                        emailService.AddToQueue(EmailType.NameChange, "Name change confirmation", new Recipient
                        {
                            FirstName = customer.FirstName,
                            LastName  = customer.LastName,
                            Email     = customer.Email
                        }, new EmailProperties {
                            Host = GetHost()
                        });
                    }



                    return(Ok());
                }
            }


            return(BadRequest());
        }
        // .........................................................................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
            });
        }