コード例 #1
0
        public async Task AlterarDevolvido(int IdVendaLivro)
        {
            Models.TbVendaLivro tabela = await ConsultarVendaLivroPorId(IdVendaLivro);

            tabela.BtDevolvido = 1;
            await context.SaveChangesAsync();
        }
コード例 #2
0
        public async Task <Models.TbVendaLivro> CadastrarVendaLivro(Models.TbVendaLivro tabela)
        {
            await context.TbVendaLivro.AddAsync(tabela);

            await context.SaveChangesAsync();

            return(tabela);
        }
コード例 #3
0
        public async Task <Models.TbVendaLivro> DeletarVendaLivro(int id)
        {
            Models.TbVendaLivro tabela = await ConsultarVendaLivroPorId(id);

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

            return(tabela);
        }
コード例 #4
0
        public async Task <Models.TbVendaLivro> DeletarVendaLivro(int id)
        {
            ValidarId(id);
            Models.TbVendaLivro vendalivro = await database.DeletarVendaLivro(id);

            if (vendalivro == null)
            {
                throw new ArgumentException("Não foi possivel deletar estar a venda deste livro.");
            }
            return(vendalivro);
        }
コード例 #5
0
        public Models.TbVendaLivro ConversorTabela(Models.Request.VendaLivroRequest request)
        {
            Models.TbVendaLivro tabela = new Models.TbVendaLivro();

            tabela.IdVenda      = request.venda;
            tabela.IdLivro      = request.livro;
            tabela.NrLivros     = request.qtd;
            tabela.VlVendaLivro = request.valor;

            return(tabela);
        }
コード例 #6
0
        public async Task <Models.TbVendaLivro> AlterarVendaLivro(int id, Models.TbVendaLivro novaTabela)
        {
            Models.TbVendaLivro tabela = await ConsultarVendaLivroPorId(id);

            tabela.IdLivro      = novaTabela.IdLivro;
            tabela.IdVenda      = novaTabela.IdVenda;
            tabela.NrLivros     = novaTabela.NrLivros;
            tabela.VlVendaLivro = novaTabela.VlVendaLivro;
            await context.SaveChangesAsync();

            return(tabela);
        }
コード例 #7
0
        public async Task <ActionResult <Models.Response.VendaLivroResponse> > AlterarVendaLivro(int idvendalivro, Models.Request.VendaLivroRequest request)
        {
            try
            {
                Models.TbVendaLivro tabela = conversor.ConversorTabela(request);
                tabela = await business.AlterarVendaLivroBusiness(idvendalivro, tabela);

                return(conversor.ConversorResponse(tabela));
            }
            catch (System.Exception ex)
            {
                return(new NotFoundObjectResult(new Models.Response.ErroResponse(404, ex.Message)));
            }
        }
コード例 #8
0
        public async Task <ActionResult <Models.Response.VendaLivroResponse> > CadastrarVendaLivro(Models.Request.VendaLivroRequest request)
        {
            try
            {
                Models.TbVendaLivro tabela = conversor.ConversorTabela(request);
                tabela = await business.CadastrarBusiness(tabela);

                return(conversor.ConversorResponse(tabela));
            }
            catch (System.Exception ex)
            {
                return(BadRequest(new Models.Response.ErroResponse(400, ex.Message)));
            }
        }
コード例 #9
0
        public Models.Response.RelatorioVendaLivro ConversorRelatorioVendaLivro(Models.TbVendaLivro tabela)
        {
            Models.Response.RelatorioVendaLivro response = new Models.Response.RelatorioVendaLivro();

            response.id         = tabela.IdVendaLivro;
            response.idlivro    = tabela.IdLivro;
            response.nome_livro = tabela.IdLivroNavigation.NmLivro;
            response.qtd        = tabela.NrLivros;
            response.lancamento = tabela.IdLivroNavigation.DtLancamento;

            response.valor_venda   = Convert.ToDouble(tabela.IdLivroNavigation.VlPrecoVenda);
            response.total_vendido = Convert.ToDouble(response.valor_venda * response.qtd);

            return(response);
        }
コード例 #10
0
        public Models.Response.VendaLivroResponse ConversorResponse(Models.TbVendaLivro tabela)
        {
            Models.Response.VendaLivroResponse response       = new Models.Response.VendaLivroResponse();
            Utils.Conversor.LivroConversor     conversorLivro = new Utils.Conversor.LivroConversor();

            response.id        = tabela.IdVendaLivro;
            response.venda     = tabela.IdVenda;
            response.livro     = tabela.IdLivro;
            response.qtd       = tabela.NrLivros;
            response.valor     = tabela.VlVendaLivro;
            response.devolvido = tabela.BtDevolvido;
            response.livroInfo = conversorLivro.Conversor(tabela.IdLivroNavigation);

            return(response);
        }
コード例 #11
0
        public async Task <Models.TbVendaLivro> AlterarVendaLivroBusiness(int id, Models.TbVendaLivro novo)
        {
            ValidarId(novo.IdLivro);
            ValidarId(novo.IdVenda);
            if (novo.NrLivros <= 0)
            {
                throw new ArgumentException("Quantidade do livro " + novo.IdLivroNavigation.NmLivro + " é invalida");
            }
            novo.VlVendaLivro = novo.IdLivroNavigation.VlPrecoVenda;
            if (novo.VlVendaLivro <= 0)
            {
                throw new ArgumentException("Valor do livro " + novo.IdLivroNavigation.NmLivro + " é invalida");
            }
            Models.TbVendaLivro vendalivro = await database.AlterarVendaLivro(id, novo);

            if (vendalivro.IdVendaLivro <= 0)
            {
                throw new ArgumentException("Não foi possivel Cadastrar esta venda livro");
            }
            return(novo);
        }