Exemple #1
0
        public bool AddNewFeedbackMail(Notification notification, User addedFor, int feedbackId)
        {
            User         addedByUser  = UserDataAccesor.GetUserById(notification.AddedBy);
            EmailContent emailContent = GetEmailContent(notification
                                                        , addedByUser
                                                        , notification.Title);

            emailContent.EmailRecipients.Add(new EmailRecipient
            {
                EmailAddress       = addedFor.Email,
                EmailRecipientType = (int)Common.Enumeration.EmailRecipientType.To
            });


            foreach (var user in UnitOfWork.EmailAlertSubscriptionRepository.GetAllSubscribedMentors(addedFor.UserId)
                     .Where(user => user.SubscribedByUserId != addedByUser.UserId))
            {
                emailContent.EmailRecipients.Add(new EmailRecipient
                {
                    EmailAddress       = user.User.Email,
                    EmailRecipientType = (int)Common.Enumeration.EmailRecipientType.CarbonCopy
                });
            }

            UnitOfWork.EmailRepository.Add(emailContent); //TODO:EmailRepository needs to be EmailContentRepository.
            return(UnitOfWork.Commit() > 0);
        }
Exemple #2
0
        public bool AddSessionMail(Notification notification, Common.Entity.Session session)
        {
            User         addedByUser  = UserDataAccesor.GetUserById(notification.AddedBy);
            EmailContent emailContent = GetEmailContent(notification
                                                        , addedByUser
                                                        , notification.Title);

            foreach (var user in UnitOfWork.SessionRepository.GetSessionWithAttendees(session.Id).UserSessionMappings)
            {
                emailContent.EmailRecipients.Add(new EmailRecipient
                {
                    EmailAddress       = user.User1.Email,
                    EmailRecipientType = (int)Common.Enumeration.EmailRecipientType.To
                });
            }

            emailContent.EmailRecipients.Add(new EmailRecipient
            {
                EmailAddress       = addedByUser.Email,
                EmailRecipientType = (int)Common.Enumeration.EmailRecipientType.CarbonCopy
            });

            UnitOfWork.EmailRepository.Add(emailContent); //TODO:EmailRepository needs to be EmailContentRepository.
            return(UnitOfWork.Commit() > 0);
        }
Exemple #3
0
        public bool AddNewDiscussionMail(Notification notification)
        {
            User addedByUser = UserDataAccesor.GetUserById(notification.AddedBy);
            List <EmailAlertSubscription> subscriptionList = UnitOfWork.EmailAlertSubscriptionRepository
                                                             .GetAllSubscribedMentors(addedByUser.UserId)
                                                             .Where(x => x.SubscribedByUserId != addedByUser.UserId)
                                                             .Distinct()
                                                             .ToList();

            if (!subscriptionList.Any())
            {
                return(true);                         // escape the routine if no one is subscribed to this trainee.
            }
            EmailContent emailContent = GetEmailContent(notification, addedByUser, notification.Title);

            foreach (var user in subscriptionList)
            {
                emailContent.EmailRecipients.Add(new EmailRecipient
                {
                    EmailAddress       = user.User.Email,
                    EmailRecipientType = (int)Common.Enumeration.EmailRecipientType.To
                });
            }

            UnitOfWork.EmailRepository.Add(emailContent);
            return(UnitOfWork.Commit() > 0);
        }
Exemple #4
0
 private EmailContent GetEmailContent(Notification notification, User addedBy, string title)
 {
     return(new EmailContent
     {
         BodyText = GenerateFeedbackMailBody(notification.Link, addedBy, title),
         Attempts = 0,
         IsRichBody = true,
         SubjectText = notification.Title,
         TaskSchedulerJobId = 2,
         IsSent = false
     });
 }
Exemple #5
0
        public bool AddNewDiscussionThreadMail(Notification notification, int discussionPostId)
        {
            User addedByUser = UserDataAccesor.GetUserById(notification.AddedBy);
            ForumDiscussionPost           forumDiscussionPost = UnitOfWork.ForumDiscussionPostRepository.GetPostWithThreads(discussionPostId);
            List <EmailAlertSubscription> subscriptionList    = UnitOfWork.EmailAlertSubscriptionRepository
                                                                .GetAllSubscribedMentors(forumDiscussionPost.AddedBy)
                                                                .Where(x => x.SubscribedByUserId != addedByUser.UserId)
                                                                .ToList();

            EmailContent emailContent = GetEmailContent(notification, addedByUser, notification.Title);

            List <DAL.EntityFramework.User> allUsers = forumDiscussionPost.ForumDiscussionThreads.Where(x => x.AddedBy != addedByUser.UserId)
                                                       .Select(x => x.User)
                                                       .Union(subscriptionList.Select(x => x.User))
                                                       .ToList();

            if (addedByUser.UserId != forumDiscussionPost.AddedBy)
            {
                emailContent.EmailRecipients.Add(new EmailRecipient
                {
                    EmailAddress       = forumDiscussionPost.User.Email,
                    EmailRecipientType = (int)Common.Enumeration.EmailRecipientType.To
                });

                foreach (DAL.EntityFramework.User user in allUsers)
                {
                    emailContent.EmailRecipients.Add(new EmailRecipient
                    {
                        EmailAddress       = user.Email,
                        EmailRecipientType = (int)Common.Enumeration.EmailRecipientType.CarbonCopy
                    });
                }
            }
            else
            {
                if (!allUsers.Any())
                {
                    return(true);                 // / escape the routine if no one is subscribed to this trainee.
                }
                foreach (DAL.EntityFramework.User user in allUsers)
                {
                    emailContent.EmailRecipients.Add(new EmailRecipient
                    {
                        EmailAddress       = user.Email,
                        EmailRecipientType = (int)Common.Enumeration.EmailRecipientType.To
                    });
                }
            }
            UnitOfWork.EmailRepository.Add(emailContent);
            return(UnitOfWork.Commit() > 0);
        }
Exemple #6
0
        private string GenerateFeedbackMailBody(string link, User addedBy, string title)
        {
            var templateData = new Dictionary <string, string>
            {
                { NotificationEmailTemplateItems.DomainName, Constants.AppDomainUrl },
                { NotificationEmailTemplateItems.NotificationTitle, title },
                { NotificationEmailTemplateItems.NotificationBy, addedBy.FirstName },
                { NotificationEmailTemplateItems.NotificationByImagePath, Constants.AppDomainUrl + "/Uploads/ProfilePicture/" + addedBy.ProfilePictureName },
                { NotificationEmailTemplateItems.NotificationRedirectUrl, Constants.AppDomainUrl + "/" + link }
            };

            var template = new TemplateContentBuilder(UtilityFunctions.FetchEmailTemplateFromPath(EmailTemplatesPath.FeedbackTemplate).ToString());

            template.Fill(templateData);
            return(template.GetText());
        }