Exemple #1
0
        public void NotifyRejectedKudosLogSender(KudosLog kudosLog)
        {
            var emailRecipient = _usersDbSet.SingleOrDefault(user => user.Id == kudosLog.CreatedBy);

            if (emailRecipient == null)
            {
                return;
            }

            var organizationName            = GetOrganizationName(kudosLog.OrganizationId).ShortName;
            var subject                     = Resources.Models.Kudos.Kudos.RejectedKudosEmailSubject;
            var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organizationName);
            var kudosProfileUrl             = _appSettings.KudosProfileUrl(organizationName, kudosLog.CreatedBy);

            var emailTemplateViewModel = new KudosRejectedEmailTemplateViewModel(
                userNotificationSettingsUrl,
                kudosLog.Employee.FullName,
                kudosLog.Points,
                kudosLog.KudosTypeName,
                kudosLog.Comments,
                kudosLog.RejectionMessage,
                kudosProfileUrl);
            var body = _mailTemplate.Generate(emailTemplateViewModel, EmailTemplateCacheKeys.KudosRejected);

            _mailingService.SendEmail(new EmailDto(emailRecipient.Email, subject, body));
        }
Exemple #2
0
        private void SendMentionEmails(CommentCreatedDTO commentDto, IList <ApplicationUser> mentionedUsers, ApplicationUser commentCreator, Organization organization)
        {
            var comment = _commentService.GetCommentBody(commentDto.CommentId);
            var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organization.ShortName);
            var postUrl     = _appSettings.WallPostUrl(organization.ShortName, commentDto.PostId);
            var subject     = $"You have been mentioned in the post";
            var messageBody = _markdownConverter.ConvertToHtml(comment);

            foreach (var mentionedUser in mentionedUsers)
            {
                try
                {
                    if (mentionedUser.NotificationsSettings != null && !mentionedUser.NotificationsSettings.MentionEmailNotifications)
                    {
                        continue;
                    }

                    var newMentionTemplateViewModel = new NewMentionTemplateViewModel(
                        mentionedUser.FullName,
                        commentCreator.FullName,
                        postUrl,
                        userNotificationSettingsUrl,
                        messageBody);

                    var content = _mailTemplate.Generate(newMentionTemplateViewModel, EmailTemplateCacheKeys.NewMention);

                    var emailData = new EmailDto(mentionedUser.Email, subject, content);
                    _mailingService.SendEmail(emailData);
                }
                catch (Exception e)
                {
                    _logger.Debug(e.Message, e);
                }
            }
        }
Exemple #3
0
        public void NotifyAboutNewPost(Post post, ApplicationUser postCreator)
        {
            var organization = _organizationService.GetOrganizationById(postCreator.OrganizationId);
            var wall         = _wallsDbSet.Single(w => w.Id == post.WallId);

            var destinationEmails           = _userService.GetWallUsersEmails(postCreator.Email, wall);
            var postLink                    = GetPostLink(wall.Type, wall.Id, organization.ShortName, post.Id);
            var authorPictureUrl            = _appSettings.PictureUrl(organization.ShortName, postCreator.PictureId);
            var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organization.ShortName);
            var subject = string.Format(Templates.NewWallPostEmailSubject, wall.Name, postCreator.FullName);
            var body    = _markdownConverter.ConvertToHtml(post.MessageBody);

            var emailTemplateViewModel = new NewWallPostEmailTemplateViewModel(
                GetWallTitle(wall),
                authorPictureUrl,
                postCreator.FullName,
                postLink,
                body,
                userNotificationSettingsUrl,
                GetActionButtonTitle(wall));
            var content = _mailTemplate.Generate(emailTemplateViewModel, EmailTemplateCacheKeys.NewWallPost);

            var emailData = new EmailDto(destinationEmails, subject, content);

            _mailingService.SendEmail(emailData);
        }
        private async Task SendWallSubscriberEmailsAsync(NewlyCreatedPostDto post,
                                                         IEnumerable <string> destinationEmails,
                                                         ApplicationUser postCreator,
                                                         Organization organization,
                                                         MultiwallWall wall)
        {
            var postLink = await GetPostLinkAsync(post.WallType, post.WallId, organization.ShortName, post.Id);

            var authorPictureUrl            = _appSettings.PictureUrl(organization.ShortName, postCreator.PictureId);
            var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organization.ShortName);
            var subject = string.Format(Templates.NewWallPostEmailSubject, wall.Name, postCreator.FullName);
            var body    = _markdownConverter.ConvertToHtml(post.MessageBody);

            var emailTemplateViewModel = new NewWallPostEmailTemplateViewModel(GetWallTitle(wall),
                                                                               authorPictureUrl,
                                                                               postCreator.FullName,
                                                                               postLink,
                                                                               body,
                                                                               userNotificationSettingsUrl,
                                                                               GetActionButtonTitle(wall));

            var content = _mailTemplate.Generate(emailTemplateViewModel, EmailTemplateCacheKeys.NewWallPost);

            var emailData = new EmailDto(destinationEmails, subject, content);
            await _mailingService.SendEmailAsync(emailData);
        }
Exemple #5
0
        public void NotifyAboutNewComment(Comment comment, ApplicationUser commentCreator)
        {
            var organization = _organizationService.GetOrganizationById(commentCreator.OrganizationId);

            var destinationEmails = _userService.GetPostCommentersEmails(commentCreator.Email, comment.PostId);
            var postAuthorEmail   = (comment.Post.AuthorId == comment.AuthorId) ? null : _userService.GetPostAuthorEmail(comment.Post.AuthorId);

            if (postAuthorEmail != null && destinationEmails.Contains(postAuthorEmail) == false)
            {
                destinationEmails.Add(postAuthorEmail);
            }

            if (destinationEmails.Count > 0)
            {
                var postLink                    = GetPostLink(comment.Post.Wall.Type, comment.Post.WallId, organization.ShortName, comment.Post.Id);
                var authorPictureUrl            = _appSettings.PictureUrl(organization.ShortName, commentCreator.PictureId);
                var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organization.ShortName);
                var subject = string.Format(Templates.NewPostCommentEmailSubject, CutMessage(comment.Post.MessageBody), commentCreator.FullName);
                var body    = _markdownConverter.ConvertToHtml(comment.MessageBody);

                var emailTemplateViewModel = new NewCommentEmailTemplateViewModel(
                    string.Format(Constants.BusinessLayer.Templates.PostCommentTitle, CutMessage(comment.Post.MessageBody)),
                    authorPictureUrl,
                    commentCreator.FullName,
                    postLink,
                    body,
                    userNotificationSettingsUrl,
                    Constants.BusinessLayer.Templates.DefautlActionButtonTitle);

                var content   = _mailTemplate.Generate(emailTemplateViewModel, EmailTemplateCacheKeys.NewPostComment);
                var emailData = new EmailDto(destinationEmails, subject, content);
                _mailingService.SendEmail(emailData);
            }
        }
        public async Task NotifyAboutNewServiceRequestAsync(CreatedServiceRequestDto createdServiceRequest)
        {
            var newServiceRequest = await _serviceRequestDbSet.SingleAsync(s => s.Id == createdServiceRequest.ServiceRequestId);

            var organizationName = await GetOrganizationNameAsync(newServiceRequest.OrganizationId);

            var emails = await _usersDbSet
                         .Where(x => x.ServiceRequestCategoriesAssigned.Any(y => y.Name == newServiceRequest.CategoryName))
                         .Where(x => x.Id != newServiceRequest.EmployeeId)
                         .Select(x => x.Email)
                         .ToListAsync();

            var subject = Resources.Models.ServiceRequest.ServiceRequest.EmailMessageSubject;
            var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organizationName);
            var serviceRequestUrl           = _appSettings.ServiceRequestUrl(organizationName, newServiceRequest.Id);

            var emailTemplateViewModel = new ServiceRequestEmailTemplateViewModel(userNotificationSettingsUrl,
                                                                                  newServiceRequest.Title,
                                                                                  await GetUserFullNameAsync(newServiceRequest.EmployeeId),
                                                                                  serviceRequestUrl);

            var body = _mailTemplate.Generate(emailTemplateViewModel, EmailPremiumTemplateCacheKeys.ServiceRequest);

            await _mailingService.SendEmailAsync(new EmailDto(emails, subject, body));
        }
Exemple #7
0
        private async Task NotifyCommitteeMembersAboutNewSuggestionAsync(CommitteeEntity committee, CommitteeSuggestion suggestion)
        {
            if (committee.Members == null || !committee.Members.Any())
            {
                return;
            }

            IList <string> membersEmails = committee.Members.Select(s => s.Email).ToList();

            var organizationName = await _organizationDbSet
                                   .Where(organization => organization.Id == committee.OrganizationId)
                                   .Select(organization => organization.ShortName)
                                   .FirstOrDefaultAsync();

            var committeesListUrl           = _appSettings.CommitteeSugestionUrl(organizationName);
            var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organizationName);
            var subject = string.Format(Resources.Common.CommitteeSuggestionEmailSubject, committee.Name);

            var emailTemplateViewModel = new CommitteeSuggestionEmailTemplateViewModel(userNotificationSettingsUrl,
                                                                                       committee.Name,
                                                                                       suggestion.Title,
                                                                                       suggestion.Description,
                                                                                       committeesListUrl);

            var body = _mailTemplate.Generate(emailTemplateViewModel, EmailPremiumTemplateCacheKeys.CommitteeSuggestion);

            await _mailingService.SendEmailAsync(new EmailDto(membersEmails, subject, body));
        }
        public void SendEmailNotification(CommentCreatedDTO commentDto)
        {
            var commentCreator = _userService.GetApplicationUser(commentDto.CommentCreator);
            var organization   = _organizationService.GetOrganizationById(commentCreator.OrganizationId);

            var destinationEmails = GetPostWatchersEmails(commentCreator.Email, commentDto.PostId, commentCreator.Id);

            if (destinationEmails.Count <= 0)
            {
                return;
            }

            var comment                     = LoadComment(commentDto.CommentId);
            var postLink                    = GetPostLink(commentDto.WallType, commentDto.WallId, organization.ShortName, commentDto.PostId);
            var authorPictureUrl            = _appSettings.PictureUrl(organization.ShortName, commentCreator.PictureId);
            var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organization.ShortName);
            var subject                     = string.Format(Templates.NewPostCommentEmailSubject, CutMessage(comment.Post.MessageBody), commentCreator.FullName);
            var body = _markdownConverter.ConvertToHtml(comment.MessageBody);

            var emailTemplateViewModel = new NewCommentEmailTemplateViewModel(
                string.Format(Constants.BusinessLayer.Templates.PostCommentTitle, CutMessage(comment.Post.MessageBody)),
                authorPictureUrl,
                commentCreator.FullName,
                postLink,
                body,
                userNotificationSettingsUrl,
                Constants.BusinessLayer.Templates.DefautlActionButtonTitle);

            var content   = _mailTemplate.Generate(emailTemplateViewModel, EmailTemplateCacheKeys.NewPostComment);
            var emailData = new EmailDto(destinationEmails, subject, content);

            _mailingService.SendEmail(emailData);
        }
Exemple #9
0
        public async Task NotifyRemovedEventParticipantsAsync(string eventName, Guid eventId, int orgId, IEnumerable <string> users)
        {
            var organization = await _organizationService.GetOrganizationByIdAsync(orgId);

            var emails = await _usersDbSet
                         .Where(u => users.Contains(u.Id))
                         .Select(u => u.Email)
                         .ToListAsync();

            var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organization.ShortName);
            var eventUrl = _appSettings.EventUrl(organization.ShortName, eventId.ToString());

            var emailTemplateViewModel = new EventParticipantExpelledEmailTemplateViewModel(userNotificationSettingsUrl, eventName, eventUrl);
            var emailBody = _mailTemplate.Generate(emailTemplateViewModel, EmailPremiumTemplateCacheKeys.EventParticipantExpelled);

            await _mailingService.SendEmailAsync(new EmailDto(emails, Resources.Models.Events.Events.ResetParticipantListEmailSubject, emailBody));
        }
Exemple #10
0
        private void SendBirthdayReminder(IEnumerable <ApplicationUser> employees, string organizationName)
        {
            var currentOrganization = _organizationsDbSet
                                      .First(name => name.ShortName == organizationName);

            var receivers = _roleService.GetAdministrationRoleEmails(currentOrganization.Id);
            var model     = new BirthdaysNotificationTemplateViewModel(GetFormattedEmployeesList(employees, organizationName, currentOrganization.ShortName), _appSettings.UserNotificationSettingsUrl(organizationName));
            var content   = _mailTemplate.Generate(model, EmailTemplateCacheKeys.BirthdaysNotification);
            var emailData = new EmailDto(receivers, Resources.Emails.Templates.BirthdaysNotificationEmailSubject, content);

            _mailingService.SendEmail(emailData);
        }
Exemple #11
0
        public void SendConfirmedNotificationEmail(string userEmail, UserAndOrganizationDTO userAndOrg)
        {
            var organizationNameAndContent = _organizationDbSet
                                             .Where(organization => organization.Id == userAndOrg.OrganizationId)
                                             .Select(organization => new { organization.ShortName, organization.WelcomeEmail })
                                             .FirstOrDefault();

            if (organizationNameAndContent == null)
            {
                return;
            }

            var mainPageUrl     = _appSettings.ClientUrl;
            var userSettingsUrl = _appSettings.UserNotificationSettingsUrl(organizationNameAndContent.ShortName);
            var subject         = string.Format(Resources.Common.NewUserConfirmedNotificationEmailSubject);

            var emailTemplateViewModel = new UserConfirmationEmailTemplateViewModel(userSettingsUrl, mainPageUrl, organizationNameAndContent.WelcomeEmail);

            var body = _mailTemplate.Generate(emailTemplateViewModel, EmailTemplateCacheKeys.UserConfirmation);

            _mailingService.SendEmail(new EmailDto(userEmail, subject, body));
        }
        public void SendEmail(TakenBookDTO takenBook)
        {
            var organizationName = _organizationsDbSet
                                   .Where(organization => organization.Id == takenBook.OrganizationId)
                                   .Select(organization => organization.ShortName)
                                   .FirstOrDefault();

            var userEmail = _usersDbSet
                            .Where(u => u.Id == takenBook.UserId)
                            .Select(u => u.Email)
                            .First();

            var subject = Resources.Models.Books.Books.EmailSubject;
            var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organizationName);
            var bookUrl = _appSettings.BookUrl(organizationName, takenBook.BookOfficeId, takenBook.OfficeId);

            var emailTemplateViewModel = new BookTakenEmailTemplateViewModel(userNotificationSettingsUrl, takenBook.Title, takenBook.Author, bookUrl);
            var body = _mailTemplate.Generate(emailTemplateViewModel, EmailTemplateCacheKeys.BookTaken);

            _mailingService.SendEmail(new EmailDto(userEmail, subject, body));
        }
Exemple #13
0
        private async Task SendLoyaltyBotNotificationAsync(AwardedKudosEmployeeDto kudosLog)
        {
            var organization = await GetOrganizationAsync(kudosLog.OrganizationId);

            var employee = await _employeeDbSet.SingleAsync(s => s.Id == kudosLog.EmployeeId);

            var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organization.ShortName);
            var kudosProfileUrl             = _appSettings.KudosProfileUrl(organization.ShortName, kudosLog.EmployeeId);
            var subject = Resources.Models.Kudos.Kudos.EmailSubject;

            var emailTemplateViewModel = new LoyaltyKudosReceivedDecreasedEmailTemplateViewModel(userNotificationSettingsUrl,
                                                                                                 kudosLog.Points,
                                                                                                 kudosLog.KudosTypeName,
                                                                                                 organization.Name,
                                                                                                 kudosLog.Comments,
                                                                                                 kudosProfileUrl);

            var body = _mailTemplate.Generate(emailTemplateViewModel, EmailPremiumTemplateCacheKeys.LoyaltyKudosReceived);

            await _mailingService.SendEmailAsync(new EmailDto(employee.Email, subject, body));
        }
        public async Task RemindAboutBooksAsync(int daysBefore)
        {
            var bookTookBefore = DateTime.UtcNow.AddDays(-daysBefore);

            var booksToRemind = await _booksDbSet
                                .Include(p => p.BookOffice)
                                .Where(p => p.TakenFrom < bookTookBefore && p.Returned == null)
                                .Select(MapBookLogToBookRemindDto())
                                .ToListAsync();

            foreach (var bookToRemind in booksToRemind)
            {
                try
                {
                    var user = await _userService.GetApplicationUserOrDefaultAsync(bookToRemind.ApplicationUserId);

                    if (user == null)
                    {
                        continue;
                    }

                    var organization = await _organizationService.GetOrganizationByIdAsync(bookToRemind.OrganizationId);

                    var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organization.ShortName);
                    var subject       = $"Book reminder: \"{bookToRemind.Title}\"";
                    var bookUrl       = _appSettings.BookUrl(organization.ShortName, bookToRemind.BookOfficeId, bookToRemind.OfficeId);
                    var formattedDate = $"{bookToRemind.TakenFrom:D}";

                    var bookRemindTemplateViewModel = new BookReminderEmailTemplateViewModel(bookToRemind.Title, bookToRemind.Author, formattedDate, bookUrl, user.FullName, userNotificationSettingsUrl);
                    var content = _mailTemplate.Generate(bookRemindTemplateViewModel, EmailPremiumTemplateCacheKeys.BookRemind);

                    var emailData = new EmailDto(user.Email, subject, content);
                    await _mailingService.SendEmailAsync(emailData);
                }
                catch (Exception e)
                {
                    _logger.Debug(e.Message, e);
                }
            }
        }
Exemple #15
0
        public async Task ReportBookAsync(BookReportDto bookReport, UserAndOrganizationDto userAndOrg)
        {
            var reportedOfficeBook = await _bookOfficesDbSet
                                     .Include(p => p.Book)
                                     .FirstAsync(p => p.Id == bookReport.BookOfficeId);

            var user = await _userService.GetApplicationUserAsync(userAndOrg.UserId);

            var receivers = await _roleService.GetAdministrationRoleEmailsAsync(userAndOrg.OrganizationId);

            var organization = await _organizationService.GetOrganizationByIdAsync(userAndOrg.OrganizationId);

            var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organization.ShortName);
            var bookUrl = _appSettings.BookUrl(organization.ShortName, bookReport.BookOfficeId, reportedOfficeBook.OfficeId);

            var subject = $"Reported book: {reportedOfficeBook.Book.Title}";
            var bookReportTemplateViewModel = new BookReportEmailTemplateViewModel(reportedOfficeBook.Book.Title, reportedOfficeBook.Book.Author,
                                                                                   bookReport.Report, bookReport.Comment, bookUrl, user.FullName, userNotificationSettingsUrl);

            var content   = _mailTemplate.Generate(bookReportTemplateViewModel, EmailPremiumTemplateCacheKeys.BookReport);
            var emailData = new EmailDto(receivers, subject, content);

            await _mailingService.SendEmailAsync(emailData);
        }