Exemple #1
0
        public async Task <ActionResult <Models.Response.LivroCompleto> > ConsultarLivroId(int idlivro, int idcliente)
        {
            try
            {
                Models.TbLivro livro = await business.ConsultarLivroIdBusiness(idlivro);

                Models.Response.LivroCompleto response = ConversorLivro.ConversorCompleto(livro);

                if (livro.TbFavoritos.Count != 0 && livro.TbFavoritos.All(x => x.IdCliente == idcliente))
                {
                    response.livro.favorito = true;
                    Models.TbFavoritos a = livro.TbFavoritos.FirstOrDefault(x => x.IdCliente == idcliente && x.IdLivro == idlivro);
                    response.favorito = conversor.ConversorResponse(a);
                }
                else
                {
                    response.livro.favorito = false;
                }

                return(response);
            }
            catch (System.Exception ex)
            {
                return(NotFound(
                           new Models.Response.ErroResponse(404, ex.Message)
                           ));
            }
        }
Exemple #2
0
        public Models.Response.FavoritoResponse ConversorResponse(Models.TbFavoritos tabela)
        {
            Models.Response.FavoritoResponse response = new Models.Response.FavoritoResponse();

            response.id    = tabela.IdFavoritos;
            response.livro = tabela.IdLivro;

            if (tabela.IdLivroNavigation != null)
            {
                response.nome       = tabela.IdLivroNavigation.NmLivro;
                response.descricao  = tabela.IdLivroNavigation.DsLivro;
                response.editora    = tabela.IdLivroNavigation.IdEditoraNavigation.NmEditora;
                response.lancamento = tabela.IdLivroNavigation.DtLancamento;
            }

            if (tabela.IdLivroNavigation.TbLivroAutor == null)
            {
                response.atores = null;
            }
            else
            {
                response.atores = tabela.IdLivroNavigation.TbLivroAutor.Select(x => x.IdAutorNavigation.NmAutor).ToList();
            }
            if (tabela.IdLivroNavigation.TbEstoque.Count <= 0 || tabela.IdLivroNavigation.TbEstoque == null)
            {
                response.qtd = 0;
            }
            else
            {
                response.qtd = tabela.IdLivroNavigation.TbEstoque.FirstOrDefault(x => x.IdLivro == response.livro).NrQuantidade;
            }

            return(response);
        }
        public async Task <Models.TbFavoritos> InserirFavoritos(Models.TbFavoritos tabela)
        {
            await db.TbFavoritos.AddAsync(tabela);

            await db.SaveChangesAsync();

            return(tabela);
        }
        public async Task <Models.TbFavoritos> RemoverFavoritosPorId(int idfavorito)
        {
            Models.TbFavoritos favorito = await this.ConsultarFavoritosPorId(idfavorito);

            db.TbFavoritos.Remove(favorito);
            await db.SaveChangesAsync();

            return(favorito);
        }
Exemple #5
0
        public Models.TbFavoritos ConversorTabela(Models.Request.FavoritoRequest request)
        {
            Models.TbFavoritos tabela = new Models.TbFavoritos();

            tabela.IdLivro    = request.livro;
            tabela.IdCliente  = request.cliente;
            tabela.DtInclusao = DateTime.Now;

            return(tabela);
        }
        public async Task <Models.TbFavoritos> ConsultarFavoritosPorId(int idfavorito)
        {
            ValidarId(idfavorito);
            Models.TbFavoritos favorito = await database.ConsultarFavoritosPorId(idfavorito);

            if (favorito == null)
            {
                new ArgumentException("Não foi possivel encontrar o livro na lista de favoritos");
            }
            return(favorito);
        }
        public async Task <Models.TbFavoritos> AlterarFavoritosPorId(int idfavorito, Models.TbFavoritos novo)
        {
            Models.TbFavoritos favorito = await this.ConsultarFavoritosPorId(idfavorito);

            favorito.IdLivro    = novo.IdLivro;
            favorito.IdCliente  = novo.IdCliente;
            favorito.DtInclusao = novo.DtInclusao;

            await db.SaveChangesAsync();

            return(favorito);
        }
        public async Task <Models.TbFavoritos> RemoverFavoritosPorId(int idfavorito)
        {
            ValidarId(idfavorito);

            Models.TbFavoritos favorito = await database.RemoverFavoritosPorId(idfavorito);

            if (favorito == null)
            {
                throw new ArgumentException("Não foi possivel alterar este livro na lista de favoritos.");
            }
            return(favorito);
        }
        public async Task <Models.TbFavoritos> AlterarFavoritosPorId(int idfavorito, Models.TbFavoritos novo)
        {
            ValidarId(novo.IdCliente);
            ValidarId(novo.IdLivro);
            Models.TbFavoritos favorito = await this.AlterarFavoritosPorId(idfavorito, novo);

            if (favorito == null)
            {
                throw new ArgumentException("Não foi possivel alterar este livro na lista de favoritos.");
            }
            return(favorito);
        }
Exemple #10
0
        public async Task <ActionResult <Models.Response.FavoritoResponse> > AlterarResponse(int idfavorito, Models.Request.FavoritoRequest request)
        {
            try
            {
                Models.TbFavoritos tabela = conversor.ConversorTabela(request);
                tabela = await business.AlterarFavoritosPorId(idfavorito, tabela);

                return(conversor.ConversorResponse(tabela));
            }
            catch (System.Exception ex)
            {
                return(new NotFoundObjectResult(new Models.Response.ErroResponse(404, ex.Message)));
            }
        }
Exemple #11
0
        public async Task <ActionResult> InserirFavarito(Models.Request.FavoritoRequest request)
        {
            try
            {
                Models.TbFavoritos tabela = conversor.ConversorTabela(request);
                tabela = await business.InserirBusiness(tabela);

                return(Ok());
            }
            catch (System.Exception ex)
            {
                return(BadRequest(new Models.Response.ErroResponse(400, ex.Message)));
            }
        }
Exemple #12
0
        public async Task <ActionResult> RemoverFavorito(int idfavorito)
        {
            try
            {
                Models.TbFavoritos favorito = await business.RemoverFavoritosPorId(idfavorito);

                return(Ok());
            }
            catch (System.Exception ex)
            {
                return(NotFound(
                           new Models.Response.ErroResponse(404, ex.Message)
                           ));
            }
        }
        public async Task <Models.TbFavoritos> InserirBusiness(Models.TbFavoritos novo)
        {
            ValidarId(novo.IdLivro);
            ValidarId(novo.IdCliente);

            List <Models.TbFavoritos> tabela = await this.ListarfavoritosBusiness(novo.IdCliente);

            if (tabela.Any(x => x.IdLivro == novo.IdLivro))
            {
                throw new ArgumentException("Item já adicionado a lista de favoritos, não é possivel adicionado novamente.");
            }

            Models.TbFavoritos favoritos = await database.InserirFavoritos(novo);

            if (favoritos == null)
            {
                throw new ArgumentException("Não foi possivel adicionar o livro aos favoritos.");
            }
            return(favoritos);
        }
        public async Task <Models.TbFavoritos> ConsultarFavoritosPorId(int idfavorito)
        {
            Models.TbFavoritos favorito = await db.TbFavoritos.FirstOrDefaultAsync(x => x.IdFavoritos == idfavorito);

            return(favorito);
        }