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);
        }
        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));
        }
        public async Task NotifyRejectedKudosLogSenderAsync(KudosLog kudosLog)
        {
            var emailRecipient = await _usersDbSet.SingleOrDefaultAsync(user => user.Id == kudosLog.CreatedBy);

            if (emailRecipient == null)
            {
                return;
            }

            var organizationName            = (await GetOrganizationNameAsync(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);
            await _mailingService.SendEmailAsync(new EmailDto(emailRecipient.Email, subject, body));
        }
Esempio n. 4
0
        public async Task SendInvitationAsync(EventJoinValidationDto @event, IEnumerable <string> userIds, int orgId)
        {
            var emails = await _usersDbSet
                         .Where(u => userIds.Contains(u.Id))
                         .Select(u => u.Email)
                         .ToListAsync();

            var calendarEvent = MapToCalendarEvent(@event);

            await AddEventLinkToDescriptionAsync(calendarEvent, @event.Id, orgId);

            var calendar = new Ical.Net.Calendar();

            calendar.Events.Add(calendarEvent);

            var serializedCalendar = new CalendarSerializer().SerializeToString(calendar);
            var calByteArray       = Encoding.UTF8.GetBytes(serializedCalendar);
            var emailDto           = new EmailDto(emails, $"Invitation: {@event.Name} @ {@event.StartDate.ToString("d")}", "");

            using (var stream = new MemoryStream(calByteArray))
            {
                emailDto.Attachment = new MailAttachment(stream, "invite.ics");
                await _mailingService.SendEmailAsync(emailDto);
            }
        }
Esempio n. 5
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));
        }
        private async Task SendEmailAsync(string userEmail, IEnumerable <Post> wallPosts, string organizationShortName)
        {
            var messageBody = GetMessageBody(wallPosts, organizationShortName);

            var email = new EmailDto(userEmail, BusinessLayerConstants.ShroomsInfoEmailSubject, messageBody);

            await _emailService.SendEmailAsync(email);
        }
Esempio n. 7
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));
        }
Esempio n. 8
0
        public async Task SubmitTicketAsync(UserAndOrganizationDto userAndOrganization, SupportDto support)
        {
            var currentApplicationUser = await _applicationUsers.SingleAsync(u => u.Id == userAndOrganization.UserId);

            var email = new EmailDto(currentApplicationUser.FullName, currentApplicationUser.Email, _applicationSettings.SupportEmail, $"{support.Type}: {support.Subject}", support.Message);

            await _mailingService.SendEmailAsync(email, true);
        }
Esempio n. 9
0
        public async Task <ActionResult> SendEmailConfirmation(string userName)
        {
            string userId = await _userDataService.GetIdByUserName(userName);

            UserDTO user = await _userDataService.GetUserInfo(userId);

            string code = await _mailingService.GenerateEmailToken(user);

            var url = Url.Action("ConfirmEmail", "Email", new
            {
                area   = "User",
                userId = user.Id,
                code   = code
            }, protocol: Request.Url.Scheme);
            await _mailingService.SendEmailAsync(user.Id, "TestingSystem", $"<a href='{url}'>Confirm email with this link</a>");

            return(View("ConfirmEmail"));
        }
Esempio n. 10
0
        public async Task <ActionResult> _GiveAdminStatus(string userId)
        {
            OperationDetails result = await _userManagementService.GiveAdminStatus(userId);

            if (result.Succeeded)
            {
                UserDTO userDto = await _userDataService.GetUserInfo(userId);

                await _mailingService.SendEmailAsync(userId, "TestingSystem", "Admin status is given to you!");

                TempData["PartialMessageSuccess"] = result.Message;
            }
            else
            {
                TempData["PartialMessageFailure"] = result.Message;
            }

            return(RedirectToAction("_ExtendedAdminUserSearch", "Panel"));
        }
        private async Task SendBirthdayReminderAsync(IEnumerable <ApplicationUser> employees, string organizationName)
        {
            var currentOrganization = await _organizationsDbSet.FirstAsync(name => name.ShortName == organizationName);

            var receivers = await _roleService.GetAdministrationRoleEmailsAsync(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);

            await _mailingService.SendEmailAsync(emailData);
        }
Esempio n. 12
0
        public async Task SendConfirmedNotificationEmailAsync(string userEmail, UserAndOrganizationDto userAndOrg)
        {
            var organizationNameAndContent = await _organizationDbSet
                                             .Where(organization => organization.Id == userAndOrg.OrganizationId)
                                             .Select(organization => new { organization.ShortName, organization.WelcomeEmail })
                                             .FirstOrDefaultAsync();

            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);

            await _mailingService.SendEmailAsync(new EmailDto(userEmail, subject, body));
        }
        private async Task SendMentionEmailsAsync(CommentCreatedDto commentDto, IList <ApplicationUser> mentionedUsers, ApplicationUser commentCreator, Organization organization)
        {
            var comment = await _commentService.GetCommentBodyAsync(commentDto.CommentId);

            var          userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organization.ShortName);
            var          postUrl     = _appSettings.WallPostUrl(organization.ShortName, commentDto.PostId);
            const string subject     = "You have been mentioned in the post";
            var          messageBody = _markdownConverter.ConvertToHtml(comment);

            foreach (var mentionedUser in mentionedUsers)
            {
                try
                {
                    if (mentionedUser.NotificationsSettings?.MentionEmailNotifications == false)
                    {
                        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);
                    await _mailingService.SendEmailAsync(emailData);
                }
                catch (Exception e)
                {
                    _logger.Debug(e.Message, e);
                }
            }
        }
Esempio n. 14
0
        public async void AddReviewText(long chatId, string text)
        {
            var review = _reviewCache.FirstOrDefault(v => v.ChatId == chatId);

            if (review == null)
            {
                throw new AggregateException($"Trying to add Text to null object, chatId: {chatId}, value: {text}.");
            }
            else
            {
                review.Text = text;
                if (!_env.IsDevelopment())
                {
                    await _mailingService.SendEmailAsync(review);
                }
                _reviewCache.Remove(review);
            }
        }
Esempio n. 15
0
        public async Task <Unit> Handle(ResetPasswordRequest request, CancellationToken cancellationToken)
        {
            var user = await userManager.FindByEmailAsync(request.Email);

            if (user == null)
            {
                throw new NotExistentUserException();
            }

            var token = await userManager.GeneratePasswordResetTokenAsync(user);

            var model = MailModel.Create(
                "Recupero de contraseña",
                new ResetPasswordEmailData(token, $"{frontendOptions.Url}{frontendOptions.ForgotPassword}"));

            await mailingService.SendEmailAsync(
                user.Email, model.Subject, await request.GetEmailBody(model));

            return(Unit.Value);
        }
Esempio n. 16
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 SendEmailAsync(TakenBookDto takenBook)
        {
            var organizationName = await _organizationsDbSet
                                   .Where(organization => organization.Id == takenBook.OrganizationId)
                                   .Select(organization => organization.ShortName)
                                   .FirstOrDefaultAsync();

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

            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, EmailPremiumTemplateCacheKeys.BookTaken);

            await _mailingService.SendEmailAsync(new EmailDto(userEmail, subject, body));
        }
Esempio n. 18
0
        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);
                }
            }
        }
Esempio n. 19
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);
        }
        public async Task <IActionResult> SendMail([FromForm] MailRequestDto dto)
        {
            await _mailingService.SendEmailAsync(dto.ToEmail, dto.Subject, dto.Body, dto.Attachments);

            return(Ok());
        }