Esempio n. 1
0
        private async Task <List <EmailMessage> > PrepareMail()
        {
            List <EmailMessage> emailMessages = new List <EmailMessage>();
            // Get template content from SendGrid
            SendGridTemplateDto template = await _sendGridService.GetMailTemplate(_mailConfigDto.TemplateId);

            // Get recepients and projects
            List <ProjectEntity> projects = await _projectStorage.FindAsync();

            List <UserEntity> users = await _userStorage.FindAsync();

            if (projects.Count() == 0 || users.Count() == 0)
            {
                return(emailMessages);
            }

            foreach (UserEntity user in users)
            {
                // Skip if user has no technologies listed
                if (user.UserTechnologies.Count == 0)
                {
                    continue;
                }

                List <ProjectEntity> matchingProjects = new List <ProjectEntity>();

                foreach (ProjectEntity project in projects)
                {
                    // Skip if project has no technologies listed
                    if (project.ProjectTechnologies.Count == 0)
                    {
                        continue;
                    }

                    IEnumerable <string> userTechnologies    = user.UserTechnologies.Select(userTech => userTech.Name);
                    IEnumerable <string> projectTechnologies = project.ProjectTechnologies.Select(projectTech => projectTech.Name);

                    var intersection = userTechnologies.Intersect(projectTechnologies);
                    if (intersection.Count() > 0)
                    {
                        matchingProjects.Add(project);
                    }
                }

                List <ProjectEntity> projectRecommendations = SelectNRandomProjects(matchingProjects, _numberOfProjectRecommendations);
                EmailMessage         message = BuildProjectRecommendationsMessage(user, projectRecommendations, template);
                emailMessages.Add(message);
            }

            return(emailMessages);
        }
Esempio n. 2
0
        private async Task <List <EmailMessage> > PrepareMail()
        {
            List <EmailMessage> emailMessages = new List <EmailMessage>();
            SendGridTemplateDto template      = await _sendGridService.GetMailTemplate(_mailConfigDto.TemplateId);

            // Get recepients and projects
            List <UserEntity> users = await _userStorage.FindAsync();

            if (users.Count() == 0)
            {
                return(emailMessages);
            }

            foreach (UserEntity user in users)
            {
                EmailMessage message = BuildLaunchShowcaseMessage(user, template);
                emailMessages.Add(message);
            }

            return(emailMessages);
        }
        public async Task <EmailMessage> PrepareFeedbackMail(NotificationDto notification)
        {
            string        feedbackContent = notification.Content;
            EmailMessage  emailMessage    = new EmailMessage();
            string        mailName        = "FeedbackMessage";
            MailConfigDto mailConfigDto   = await _mailConfig.GetConfig(mailName);

            SendGridTemplateDto template = await _sendGridService.GetMailTemplate(mailConfigDto.TemplateId);

            DTOs.Version activeTemplate = template.Versions.FirstOrDefault(v => v.Active == 1);
            emailMessage = JsonConvert.DeserializeObject <EmailMessage>(AppSettings.FeedbackRecipients);

            EmailAddress fromAddress = _fromAddress;

            emailMessage.FromAddresses.Add(fromAddress);
            emailMessage.Subject = $"{activeTemplate.Subject} {_testEmailIndicator}";
            string htmlContent      = activeTemplate.HtmlContent.Replace("{{feedbackMessage}}", feedbackContent);
            string plainTextContent = activeTemplate.PlainContent.Replace("{{feedbackMessage}}", feedbackContent);

            emailMessage.MailContent.Add("text/html", htmlContent);
            emailMessage.MailContent.Add("text/plain", plainTextContent);

            return(emailMessage);
        }