public ActionResult IncluirProduto(Produto produtoObj)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _repositorio = new ProdutoRepositorio();

                    if (_repositorio.AdicionarProduto(produtoObj))
                    {
                        ViewBag.Mensagem = "Produto cadastrado com sucesso";
                    }
                }
                return(RedirectToAction("ObterProdutos"));
            }
            catch (Exception)
            {
                return(View("ObterProdutos"));
            }
        }
Пример #2
0
        public void Insert(Product product)
        {
            if (product == null)
            {
                throw new Exception("O produto não pode ser nulo");
            }

            if (string.IsNullOrEmpty(product.Name))
            {
                throw new Exception("O produto precisa ter Name");
            }

            if (product.Type == "Outro")
            {
                if (string.IsNullOrEmpty(product.Other))
                {
                    throw new Exception("Preencha o campo outro");
                }
            }

            productRepository.AdicionarProduto(product);
        }