private void SendMentionEmails(NewlyCreatedPostDTO post, List <ApplicationUser> mentionedUsers, ApplicationUser postCreator, Organization organization) { var messageBody = _markdownConverter.ConvertToHtml(_postService.GetPostBody(post.Id)); var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organization.ShortName); var postUrl = _appSettings.WallPostUrl(organization.ShortName, post.Id); var subject = $"You have been mentioned in the post"; foreach (var mentionedUser in mentionedUsers) { try { if (mentionedUser.NotificationsSettings != null && !mentionedUser.NotificationsSettings.MentionEmailNotifications) { continue; } var newMentionTemplateViewModel = new NewMentionTemplateViewModel( mentionedUser.FullName, postCreator.FacebookEmail, 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); } } }
public void NotifyAboutNewPost(NewlyCreatedPostDTO post) { var postCreator = _userService.GetApplicationUser(post.User.UserId); 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(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); _mailingService.SendEmail(emailData); }
public void Notify(NewlyCreatedPostDTO createdPost, UserAndOrganizationHubDto userAndOrganizationHubDto) { _postNotificationService.NotifyAboutNewPost(createdPost); var membersToNotify = _userService.GetWallUserAppNotificationEnabledIds(createdPost.User.UserId, createdPost.WallId); var notificationDto = _notificationService.CreateForPost(userAndOrganizationHubDto, createdPost, createdPost.WallId, membersToNotify).GetAwaiter().GetResult(); NotificationHub.SendNotificationToParticularUsers(_mapper.Map <NotificationViewModel>(notificationDto), userAndOrganizationHubDto, membersToNotify); NotificationHub.SendWallNotification(createdPost.WallId, membersToNotify, createdPost.WallType, userAndOrganizationHubDto); }
private NewlyCreatedPostDTO MapNewlyCreatedPostToDto(Post post, UserDto user, WallType wallType) { var newlyCreatedPostDto = new NewlyCreatedPostDTO { Id = post.Id, MessageBody = post.MessageBody, PictureId = post.PictureId, Created = post.Created, CreatedBy = post.CreatedBy, User = user, WallType = wallType }; return(newlyCreatedPostDto); }
private NewlyCreatedPostDTO MapNewlyCreatedPostToDto(Post post, UserDto user, WallType wallType, IEnumerable <string> mentionedUserIds) { var newlyCreatedPostDto = new NewlyCreatedPostDTO { Id = post.Id, MessageBody = post.MessageBody, PictureId = post.PictureId, Created = post.Created, CreatedBy = post.CreatedBy, User = user, WallType = wallType, WallId = post.WallId, MentionedUsersIds = mentionedUserIds }; return(newlyCreatedPostDto); }
public void NotifyAboutNewPost(NewlyCreatedPostDTO post) { var postCreator = _userService.GetApplicationUser(post.User.UserId); var organization = _organizationService.GetOrganizationById(postCreator.OrganizationId); var wall = _wallsDbSet.Single(w => w.Id == post.WallId); var mentionedUsers = GetMentionedUsers(post.MentionedUsersIds).ToList(); var destinationEmails = _userService.GetWallUsersEmails(postCreator.Email, wall).Except(mentionedUsers.Select(x => x.Email)).ToList(); if (destinationEmails.Count > 0) { SendWallSubscriberEmails(post, destinationEmails, postCreator, organization, wall); } if (mentionedUsers.Count > 0) { SendMentionEmails(post, mentionedUsers, postCreator, organization); } }
private void SendWallSubscriberEmails(NewlyCreatedPostDTO post, List <string> destinationEmails, ApplicationUser postCreator, Organization organization, DataLayer.EntityModels.Models.Multiwall.Wall wall) { var postLink = GetPostLink(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); _mailingService.SendEmail(emailData); }
public async Task <NotificationDto> CreateForPost(UserAndOrganizationDTO userOrg, NewlyCreatedPostDTO post, int wallId, IEnumerable <string> membersToNotify) { var postType = NotificationType.WallPost; var sources = new Sources { PostId = post.Id }; switch (post.WallType) { case WallType.Events: postType = NotificationType.EventPost; sources.EventId = _eventDbSet.FirstOrDefault(x => x.WallId == wallId).Id.ToString(); break; case WallType.Project: postType = NotificationType.ProjectPost; sources.ProjectId = _projectDbSet.FirstOrDefault(x => x.WallId == wallId).Id.ToString(); break; } var wallName = await _wallDbSet .Where(x => x.Id == wallId && x.OrganizationId == userOrg.OrganizationId) .Select(s => s.Name) .SingleAsync(); var newNotification = Notification.Create(post.User.FullName, wallName, post.User.PictureId, sources, postType, userOrg.OrganizationId, membersToNotify); _notificationDbSet.Add(newNotification); await _uow.SaveChangesAsync(); return(_mapper.Map <NotificationDto>(newNotification)); }