Exemplo n.º 1
0
        public ICommandResult Handle(UpdateBooksCommand command)
        {
            //FAIL FAST VALIDATION
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(false, "An error occurred while updating the requested record", command.Notifications));
            }

            //Retrieve Author from Database
            var book = _bookRepository.GetById(command.Id).Result;

            var bookUpdate = _mapper.Map <UpdateBooksCommand, Books>(command);

            //Update the data in the database
            book.UpdateBook(bookUpdate.Title, bookUpdate.ReleaseDate, bookUpdate.ISBN, bookUpdate.Category, bookUpdate.AuthorId);

            _bookRepository.Update(book);

            //Send message to queue
            _bus.Enqueue(command, UpdateBooksCommand.QueueName);

            return(new GenericCommandResult(true, $"The book {book.Title} has been updated successfully", book));
        }
Exemplo n.º 2
0
 public GenericCommandResult Update([FromBody] UpdateBooksCommand command, [FromServices] BooksHandler handler)
 {
     _logger.LogInformation("Executing api/book to update book");
     return((GenericCommandResult)handler.Handle(command));
 }