public void Insert(Guid bookId, string reason) { //obtem o livro requisitado e o doador var bookRequested = _bookService.GetBookWithAllUsers(bookId); var bookUser = new BookUser() { BookId = bookId, UserId = new Guid(Thread.CurrentPrincipal?.Identity?.Name), Reason = reason, NickName = $"Interessado {bookRequested?.TotalInterested() + 1}" }; if (!_bookService.Any(x => x.Id == bookUser.BookId)) { throw new ShareBookException(ShareBookException.Error.NotFound); } if (_bookUserRepository.Any(x => x.UserId == bookUser.UserId && x.BookId == bookUser.BookId)) { throw new ShareBookException("O usuário já possui uma requisição para o mesmo livro."); } _bookUserRepository.Insert(bookUser); _bookUsersEmailService.SendEmailBookRequested(bookUser); _bookUsersEmailService.SendEmailBookDonor(bookUser, bookRequested); _bookUsersEmailService.SendEmailBookInterested(bookUser, bookRequested); }
public void Insert(Guid bookId, string reason) { //obtem o livro requisitado e o doador var bookRequested = _bookService.GetBookWithAllUsers(bookId); var bookUser = new BookUser() { BookId = bookId, UserId = new Guid(Thread.CurrentPrincipal?.Identity?.Name), Reason = reason, NickName = $"Interessado {bookRequested?.TotalInterested() + 1}" }; if (!_bookService.Any(x => x.Id == bookUser.BookId)) { throw new ShareBookException(ShareBookException.Error.NotFound); } if (_bookUserRepository.Any(x => x.UserId == bookUser.UserId && x.BookId == bookUser.BookId)) { throw new ShareBookException("O usuário já possui uma requisição para o mesmo livro."); } if (bookRequested.Status != BookStatus.Available) { throw new ShareBookException("Esse livro não está mais disponível para doação."); } _bookUserRepository.Insert(bookUser); // Remove da vitrine caso o número de pedidos estiver grande demais. MaxRequestsValidation(bookRequested); var sendEmailBookRequested = bool.Parse(_configuration["EmailSettings:SendEmailBookRequested"]); // TODO: não vamos precisar dessa configuração quando o email estiver enfileirado. if (sendEmailBookRequested) { _bookUsersEmailService.SendEmailBookDonor(bookUser, bookRequested).Wait(); _bookUsersEmailService.SendEmailBookInterested(bookUser, bookRequested).Wait(); } }
public void Insert(Guid bookId, string reason) { var bookUser = new BookUser() { BookId = bookId, UserId = new Guid(Thread.CurrentPrincipal?.Identity?.Name), Reason = reason }; if (!_bookService.Any(x => x.Id == bookUser.BookId)) { throw new ShareBookException(ShareBookException.Error.NotFound); } if (_bookUserRepository.Any(x => x.UserId == bookUser.UserId && x.BookId == bookUser.BookId)) { throw new ShareBookException("O usuário já possui uma requisição para o mesmo livro."); } _bookUserRepository.Insert(bookUser); _bookUsersEmailService.SendEmailBookRequested(bookUser); _bookUsersEmailService.SendEmailBookDonor(bookUser); }