Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
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);
                }
            }
        }
Exemplo n.º 3
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);
        }