コード例 #1
0
        public async Task <Models.TbLivroAutor> AlterarLivroAutor(int id, Models.TbLivroAutor novaTabela)
        {
            Models.TbLivroAutor tabela = await ConsultarPorIdLivroAutor(id);

            tabela.IdAutor = novaTabela.IdAutor;
            tabela.IdLivro = novaTabela.IdLivro;
            return(tabela);
        }
コード例 #2
0
        public async Task <Models.TbLivroAutor> CadastrarLivroAutor(Models.TbLivroAutor tabela)
        {
            await context.AddAsync(tabela);

            await context.SaveChangesAsync();

            return(tabela);
        }
コード例 #3
0
        public Models.TbLivroAutor ConversorTabela(Models.Request.LivroAutorRequest request)
        {
            Models.TbLivroAutor tabela = new Models.TbLivroAutor();

            tabela.IdLivro = request.livro;
            tabela.IdAutor = request.autor;

            return(tabela);
        }
コード例 #4
0
        public async Task <Models.TbLivroAutor> DeletarLivroAutor(int id)
        {
            Models.TbLivroAutor tabela = await ConsultarPorIdLivroAutor(id);

            context.TbLivroAutor.Remove(tabela);
            await context.SaveChangesAsync();

            return(tabela);
        }
コード例 #5
0
        public Models.Response.LivroAutorResponse ConversorResponse(Models.TbLivroAutor tabela)
        {
            Models.Response.LivroAutorResponse response = new Models.Response.LivroAutorResponse();

            response.id    = tabela.IdLivroAutor;
            response.livro = tabela.IdLivro;
            response.autor = tabela.IdAutor;

            return(response);
        }
コード例 #6
0
        public async Task <ActionResult <Models.Response.LivroAutorResponse> > AlterarLivroAutor(int idlivroautor, Models.Request.LivroAutorRequest request)
        {
            try
            {
                Models.TbLivroAutor tabela = conversor.ConversorTabela(request);
                tabela = await business.ValidarAlterarLivroAutor(idlivroautor, tabela);

                return(conversor.ConversorResponse(tabela));
            }
            catch (System.Exception ex)
            {
                return(new NotFoundObjectResult(new Models.Response.ErroResponse(404, ex.Message)));
            }
        }
コード例 #7
0
        public async Task <ActionResult <Models.Response.LivroAutorResponse> > CadastrarLivroAutor(Models.Request.LivroAutorRequest request)
        {
            try
            {
                Models.TbLivroAutor tabela = conversor.ConversorTabela(request);
                tabela = await business.ValidarCadastroLivroAutor(tabela);

                return(conversor.ConversorResponse(tabela));
            }
            catch (System.Exception ex)
            {
                return(BadRequest(new Models.Response.ErroResponse(400, ex.Message)));
            }
        }
コード例 #8
0
 public async Task <Models.TbLivroAutor> ValidarCadastroLivroAutor(Models.TbLivroAutor tabela)
 {
     ValidarId(tabela.IdLivro);
     ValidarId(tabela.IdAutor);
     return(await database.CadastrarLivroAutor(tabela));
 }
コード例 #9
0
 public async Task <Models.TbLivroAutor> ValidarAlterarLivroAutor(int id, Models.TbLivroAutor tabela)
 {
     ValidarId(tabela.IdLivro);
     ValidarId(tabela.IdAutor);
     return(await database.AlterarLivroAutor(id, tabela));
 }