public void AtualizarQuantidadeItemListaCompra(int IdListaCompra, int idItemListaCompra, int quantidade)
        {
            if (IdListaCompra == 0)
            {
                throw new ArgumentException("Informe a lista de compra");
            }

            if (idItemListaCompra == 0)
            {
                throw new ArgumentException("Informe o produto");
            }

            ItemListaCompra itemListaCompra = repositorioItemListaCompra.ObterPorId(idItemListaCompra);

            if (itemListaCompra == null || itemListaCompra.IdItemListaCompra == 0)
            {
                throw new InvalidOperationException("Item não encontrado!");
            }

            itemListaCompra.Quantidade = quantidade;

            repositorioItemListaCompra.Atualizar(itemListaCompra);

            repositorioItemListaCompra.UnitOfWork.Commit();
        }
Пример #2
0
        public void DadoEuSelecionoAOpcaoDeAdicionarProdutoEmUmaListaDeCompra_()
        {
            this.contextCestaBD        = new ContextCestaBD();
            aplListaCompra             = new AplListaCompra();
            this.repositorioConsumidor = new RepositorioConsumidor(contextCestaBD);
            this.repositorioProduto    = new RepositorioProduto(contextCestaBD);
            produtoPesquisa            = new Produto();
            lstPesquisaProduto         = new List <Produto>();
            achouProduto           = false;
            itemListaCompra        = new ItemListaCompra();
            repositorioListaCompra = new RepositorioListaCompra(contextCestaBD);

            aplListaCompra.ExcluirListaCompra(
                repositorioListaCompra.Obter(lista => lista.Nome.Contains(nomeListaTeste)).IdListaCompra
                );

            this.IdListaCompra = aplListaCompra.CriarListaCompra(nomeListaTeste, 1);
        }
        public int RemoverItemListaCompra(int IdListaCompra, int IdItemListaCompra)
        {
            if (IdListaCompra == 0)
            {
                throw new ArgumentException("Informe a lista de compra");
            }

            if (IdItemListaCompra == 0)
            {
                throw new ArgumentException("Informe o produto");
            }

            ItemListaCompra itemListaCompra = repositorioItemListaCompra.ObterPorId(IdItemListaCompra);

            repositorioItemListaCompra.Excluir(itemListaCompra);

            repositorioItemListaCompra.UnitOfWork.Commit();

            return(itemListaCompra.IdItemListaCompra);
        }
        public int AdicionarProdutoLista(int IdListaCompra, int IdProduto)
        {
            if (IdListaCompra == 0)
            {
                throw new ArgumentException("Informe a lista de compra");
            }

            if (IdProduto == 0)
            {
                throw new ArgumentException("Informe o produto");
            }

            ItemListaCompra itemListaCompra = new ItemListaCompra
            {
                ListaCompra = repositorioListaCompra.ObterPorId(IdListaCompra),
                Produto     = repositorioProduto.ObterPorId(IdProduto)
            };

            repositorioItemListaCompra.Inserir(itemListaCompra);

            repositorioItemListaCompra.UnitOfWork.Commit();

            return(itemListaCompra.IdItemListaCompra);
        }