Пример #1
0
        public async Task Executar(CadastrarLivroEntrada entrada)
        {
            if (entrada is null)
            {
                this._CadastrarLivroSaidaPort.WriteError("Entrada não pode ser nula");
                return;
            }

            ICadastroLivro CadastroLivro = await this._CadastroLivroRepository.GetCadastroLivro().ConfigureAwait(false);

            if (CadastroLivro is null)
            {
                this._CadastrarLivroSaidaPort.WriteError("Cadastro de livros não existe.");
                return;
            }


            ILivro livro = await this._CadastroLivroService.CadastrarLivro(CadastroLivro,
                                                                           new Livro()
            {
                autor = entrada.autor,
                isbn  = entrada.isbn,
                nome  = entrada.nome,
                preco = entrada.preco
            });


            await this._unitOfWork.Save().ConfigureAwait(false);

            this.BuildOutput(livro.isbn.id);
        }
Пример #2
0
        public async Task <ILivro> CadastrarLivro(ICadastroLivro CadastroLivro, Livro Livro)
        {
            if (CadastroLivro is null)
            {
                throw new ArgumentNullException(nameof(CadastroLivro));
            }

            if (Livro is null)
            {
                throw new ArgumentNullException(nameof(Livro));
            }

            ILivro livro = CadastroLivro.IncluirLivro(this._CadastroLivroFactory, Livro);

            await this._CadastroLivroRepository.Add(CadastroLivro, livro)
            .ConfigureAwait(false);

            return(livro);
        }
Пример #3
0
        public async Task <ILivro> AlterarLivro(ICadastroLivro CadastroLivro, Livro Livro)
        {
            if (CadastroLivro is null)
            {
                throw new ArgumentNullException(nameof(CadastroLivro));
            }

            if (Livro is null)
            {
                throw new ArgumentNullException(nameof(Livro));
            }

            ILivro livro = CadastroLivro.ALterarLivro(this._CadastroLivroFactory, Livro);

            if (livro != null)
            {
                await this._CadastroLivroRepository.Update(CadastroLivro, livro).ConfigureAwait(false);
            }

            return(livro);
        }
Пример #4
0
        public async Task <ILivro> ExcluirLivro(ICadastroLivro CadastroLivro, Livro Livro)
        {
            if (CadastroLivro is null)
            {
                throw new ArgumentNullException(nameof(CadastroLivro));
            }

            if (Livro is null)
            {
                throw new ArgumentNullException(nameof(Livro));
            }


            bool result = false;

            result = CadastroLivro.ExcluirLivro(this._CadastroLivroFactory, Livro);
            ILivro livro = (ILivro)Livro;

            await this._CadastroLivroRepository.Delete(CadastroLivro, livro)
            .ConfigureAwait(false);

            return(livro);
        }