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));
        }
예제 #2
0
        public async Task TakeBookAsync(BookTakeDto bookDto)
        {
            MobileBookOfficeLogsDto officeBookWithLogs;

            await _takeBookLock.WaitAsync();

            try
            {
                officeBookWithLogs = await _bookOfficesDbSet
                                     .Include(b => b.Book)
                                     .Include(b => b.BookLogs)
                                     .Where(b => b.OrganizationId == bookDto.OrganizationId && b.Id == bookDto.BookOfficeId)
                                     .Select(MapOfficeBookWithLogsToDto())
                                     .FirstOrDefaultAsync();

                await ValidateTakeBookAsync(bookDto, officeBookWithLogs);
                await BorrowBookAsync(officeBookWithLogs, bookDto);
            }
            finally
            {
                _takeBookLock.Release();
            }

            var book = new TakenBookDto
            {
                UserId         = bookDto.ApplicationUserId,
                OrganizationId = bookDto.OrganizationId,
                BookOfficeId   = bookDto.BookOfficeId
            };

            if (officeBookWithLogs != null)
            {
                book.OfficeId = officeBookWithLogs.OfficeId;
                book.Author   = officeBookWithLogs.Author;
                book.Title    = officeBookWithLogs.Title;
            }

            _asyncRunner.Run <IBooksNotificationService>(async notifier => await notifier.SendEmailAsync(book), _uow.ConnectionName);
        }