public Result <Book> Approve(Guid bookId)
        {
            var book = _repository.Get(bookId);

            if (book == null)
            {
                throw new ShareBookException(ShareBookException.Error.NotFound);
            }

            book.Approved = true;
            _repository.Update(book);

            _booksEmailService.SendEmailBookApproved(book).Wait();

            return(new Result <Book>(book));
        }
        public Result <Book> Approve(Guid bookId, DateTime?chooseDate)
        {
            var book = _repository.Find(bookId);

            if (book == null)
            {
                throw new ShareBookException(ShareBookException.Error.NotFound);
            }

            book.Approved   = true;
            book.ChooseDate = chooseDate?.Date ?? DateTime.Today.AddDays(5);
            _repository.Update(book);

            _booksEmailService.SendEmailBookApproved(book).Wait();

            return(new Result <Book>(book));
        }
Exemple #3
0
        public void Approve(Guid bookId, DateTime?chooseDate = null)
        {
            var book = _repository.Get().Include(b => b.Category).FirstOrDefault(b => b.Id == bookId);

            if (book == null)
            {
                throw new ShareBookException(ShareBookException.Error.NotFound);
            }

            book.Status     = BookStatus.Available;
            book.ChooseDate = chooseDate?.Date ?? DateTime.Today.AddDays(5);
            _repository.Update(book);

            // notifica o doador
            _booksEmailService.SendEmailBookApproved(book).Wait();

            // notifica possíveis interessados
            _booksEmailService.SendEmailBookToInterestedUsers(book).Wait();
        }
Exemple #4
0
        public Result <Book> Approve(Guid bookId, DateTime?chooseDate = null)
        {
            var book = _repository.Find(bookId);

            if (book == null)
            {
                throw new ShareBookException(ShareBookException.Error.NotFound);
            }

            book.Approved   = true;
            book.ChooseDate = chooseDate?.Date ?? DateTime.Today.AddDays(5);
            _repository.Update(book);

            // TODO: obter o usuário doador. Não o usuário logado.
            // Github issue: https://github.com/SharebookBR/sharebook-backend/issues/139
            book.UserId = new Guid(Thread.CurrentPrincipal?.Identity?.Name);
            _booksEmailService.SendEmailBookApproved(book).Wait();

            return(new Result <Book>(book));
        }
Exemple #5
0
        public void Approve(Guid bookId, DateTime?chooseDate = null)
        {
            var daysInShowcase = int.Parse(_configuration["SharebookSettings:DaysInShowcase"]);

            var book = _repository.Get().Include(b => b.Category).FirstOrDefault(b => b.Id == bookId);

            if (book == null)
            {
                throw new ShareBookException(ShareBookException.Error.NotFound);
            }

            book.Status     = BookStatus.Available;
            book.ChooseDate = chooseDate?.Date ?? DateTime.Today.AddDays(daysInShowcase);
            _repository.Update(book);

            // notifica o doador
            _booksEmailService.SendEmailBookApproved(book).Wait();

            // notifica possíveis interessados
            // todo: desacoplar o próprio enfileiramento numa outra fila.
            // aprove >> fila 1 >> fila 2 >> notifica interessados.
            // _booksEmailService.SendEmailBookToInterestedUsers(book).Wait();
        }