Ejemplo n.º 1
0
        public ActionResult Create(FormCollection form, HttpPostedFileBase imagem)
        {
            ComandaEletronica.Entity.Produto e = new Produto();
            e.Nome      = form["nome"];
            e.Preco     = decimal.Parse(form["preco"]);
            e.Descricao = form["descricao"];
            e.Categoria = Categoria.Pronto;

            e.TempoPreparo = int.Parse(form["tempoPreparo"]);
            e.Estoque      = int.Parse(form["estoque"]);


            if (imagem != null)
            {
                string[] name = imagem.FileName.Split('\\');
                e.Imagem = "/Arquivos/" + name[name.Length - 1];

                imagem.SaveAs(HostingEnvironment.ApplicationPhysicalPath + "\\Arquivos\\" + name[name.Length - 1]);
            }



            using (ProdutoModel model = new ProdutoModel())
            {
                model.Create(e);
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
 public ActionResult Create(Produto p)
 {
     if (ModelState.IsValid)
     {
         using (ProdutoModel model = new ProdutoModel())
         {
             model.Create(p);
             return(RedirectToAction("Index"));
         }
     }
     else
     {
         ViewBag.Erro = "Preencha corretamente as informações do produto.";
         return(RedirectToAction("Index"));
     }
 }
Ejemplo n.º 3
0
        public ActionResult Create(Produto p)
        {
            if (ModelState.IsValid)
            {
                p.UsuarioID = (int)Session["UsuarioId"];
                p.Vendido   = false;

                using (ProdutoModel model = new ProdutoModel())
                {
                    model.Create(p);
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                ViewBag.Erro = "Preencha a descrição da tarefa.";
                return(View());
            }
        }