private void ValidateTakeBook(BookTakeDTO bookDTO, MobileBookOfficeLogsDTO officeBookWithLogs) { var applicationUser = _userDbSet .FirstOrDefault(u => u.Id == bookDTO.ApplicationUserId); _serviceValidator.ThrowIfUserDoesNotExist(applicationUser); _serviceValidator.ThrowIfBookDoesNotExist(officeBookWithLogs != null); _serviceValidator.ChecksIfUserHasAlreadyBorrowedSameBook(officeBookWithLogs.LogsUserIDs, bookDTO.ApplicationUserId); _serviceValidator.ThrowIfBookIsAlreadyBorrowed(officeBookWithLogs); }
public void ThrowIfBookIsAlreadyBorrowed(MobileBookOfficeLogsDTO officeBookWithLogs) { if (officeBookWithLogs.LogsUserIDs != null) { var availableBooks = officeBookWithLogs.Quantity - officeBookWithLogs.LogsUserIDs.Count(); if (availableBooks < 1) { throw new BookException(Resources.Books.NoAvailableBooks); } } }
private void BorrowBook(MobileBookOfficeLogsDTO officeBookWithLogs, BookTakeDTO bookDTO) { var bookLog = new BookLog() { ApplicationUserId = bookDTO.ApplicationUserId, BookOfficeId = officeBookWithLogs.BookOfficeId, ModifiedBy = bookDTO.ApplicationUserId, Modified = DateTime.UtcNow, TakenFrom = DateTime.UtcNow, Created = DateTime.UtcNow, CreatedBy = bookDTO.ApplicationUserId, OrganizationId = bookDTO.OrganizationId, }; _bookLogsDbSet.Add(bookLog); _uow.SaveChanges(false); }
public void SendEmail(BookLog bookLog, MobileBookOfficeLogsDTO bookOffice) { var organizationName = _organizationsDbSet .Where(organization => organization.Id == bookLog.OrganizationId) .Select(organization => organization.ShortName) .FirstOrDefault(); var userEmail = _usersDbSet .Where(u => u.Id == bookLog.ApplicationUserId) .Select(u => u.Email) .First(); var subject = Resources.Models.Books.Books.EmailSubject; var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organizationName); var bookUrl = _appSettings.BookUrl(organizationName, bookOffice.BookOfficeId, bookOffice.OfficeId); var emailTemplateViewModel = new BookTakenEmailTemplateViewModel(userNotificationSettingsUrl, bookOffice.Title, bookOffice.Author, bookUrl); var body = _mailTemplate.Generate(emailTemplateViewModel, EmailTemplateCacheKeys.BookTaken); _mailingService.SendEmail(new EmailDto(userEmail, subject, body)); }