public ActionResult CadastrarIngrediente(Ingrediente ingrediente, int?Categorias)
        {
            ViewBag.Categorias = new SelectList(CategoriaDAO.RetornarCategorias(), "IdCategoria", "NomeCategoria");

            if (ModelState.IsValid)
            {
                if (Categorias != null)
                {
                    ingrediente.CategoriaIngrediente = CategoriaDAO.BuscarCategoriaPorId(Categorias);
                    if (IngredienteDAO.CadastrarIngrediente(ingrediente))
                    {
                        return(RedirectToAction("Home", "Ingrediente"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Não é possível adicionar um ingrediente com o mesmo nome!");
                        return(View(ingrediente));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Por favor, selecione uma categoria!");
                    return(View(ingrediente));
                }
            }
            else
            {
                return(View());
            }
        }
Пример #2
0
 public ActionResult Cadastrar([Bind(Include = "IngredienteId,Nome")] Ingrediente ingrediente)
 {
     if (ModelState.IsValid)
     {
         IngredienteDAO.CadastrarIngrediente(ingrediente);
         return(RedirectToAction("Cadastrar", "Ingredientes"));
     }
     ModelState.AddModelError("", "Ingrediente já cadastrado!");
     return(View(ingrediente));
 }
 public ActionResult Cadastrar(Ingrediente ingrediente)
 {
     if (ModelState.IsValid)
     {
         if (IngredienteDAO.CadastrarIngrediente(ingrediente))
         {
             return(RedirectToAction("Index", "Estoque"));
         }
         //Tratamento de erros/exceções
         return(RedirectToAction("Index", "Estoque"));
     }
     return(RedirectToAction("Index", "Estoque"));
 }
        public IHttpActionResult PostIngrediente(Ingrediente ingrediente)
        {
            if (!ModelState.IsValid || ingrediente == null)
            {
                return(BadRequest(ModelState));
            }

            if (IngredienteDAO.CadastrarIngrediente(ingrediente))
            {
                return(Created("", ingrediente));
            }
            return(Conflict());
        }
Пример #5
0
        public static void Renderizar()
        {
            Ingrediente i = new Ingrediente();

            //Storage s = new Storage();

            Console.WriteLine("\nCADASTRO DE INGREDIENTES");
            Console.WriteLine("\nDigite o nome do Ingrediente:");
            i.Nome = Console.ReadLine();
            Console.WriteLine("Digite a descrição do Ingrediente:");
            i.Descricao = Console.ReadLine();
            //Console.WriteLine("Preço do Ingrediente:");
            //i.Preco = Convert.ToDouble(Console.ReadLine());
            if (IngredienteDAO.CadastrarIngrediente(i))
            {
                Console.WriteLine("\nIngrediente Cadastrado na base de dados com sucesso!");
            }
            else
            {
                Console.WriteLine("\nIngrediente ja cadastrado");
            }
        }