Exemple #1
0
        // GET: Ingrediente

        /******************************************************************** CADASTRAR INGREDIENTE ********************************************************************/
        public ActionResult CadastrarIngrediente(String ID)
        {
            if (Session["UsuarioLogado"] == null)
            {
                return(RedirectToAction("Index", "Login"));
            }
            else if (Session["NivelAcesso"].Equals(2) || Session["NivelAcesso"].Equals(3) || Session["NivelAcesso"].Equals(4))
            {
                if (Request.HttpMethod.Equals("POST"))
                {
                    if (ID == null)
                    {
                        L.SelecionaLote(Session["NomeLote"].ToString());
                        L.VerificaLote(L.CodigoLote.ToString());
                    }
                    else
                    {
                        L.VerificaLote(ID);
                    }

                    if (L.Contador < L.Quantidadeitens)
                    {
                        try
                        {
                            I.NomeIngrediente = Request.Form["nomeIngrediente"].ToString();
                            I.QtdIngrediente  = Convert.ToInt32(Request.Form["QtdIngrediente"].ToString());

                            if (Request.Form["unidadeMedida"].Equals("Selecione uma opção"))
                            {
                                ViewBag.MensagemAtencao = "Selecione uma unidade de medida para continuar.";
                            }
                            else
                            {
                                I.UnidadeMedida = Request.Form["unidadeMedida"].ToString();
                                I.NivelRisco    = Convert.ToInt32(Request.Form["nivelRisco"].ToString());

                                if (ID == null)
                                {
                                    I.CadastrarIngrediente(L.CodigoLote.ToString());
                                    Session["CodigoLote"] = ID;
                                    String CodigoLote = Session["CodigoLote"].ToString();
                                    Session["CodigoLote"]    = null;
                                    ViewBag.MensagemmSucesso = "Cadastro realizado com sucesso!";
                                    return(RedirectToAction("ListarLotes", "Lote", CodigoLote));
                                }
                                else
                                {
                                    I.CadastrarIngrediente(ID);
                                    Session["CodigoLote"] = ID;
                                    String CodigoLote = Session["CodigoLote"].ToString();
                                    Session["CodigoLote"]   = null;
                                    ViewBag.MensagemSucesso = "Cadastro realizado com sucesso!";
                                    return(RedirectToAction("ListarLotes", "Lote", CodigoLote));
                                }
                            }
                        }
                        catch
                        {
                            ViewBag.MensagemErro = "Erro ao tentar cadastrar! Verifique todos os campos.";
                        }
                    }
                    else
                    {
                        ViewBag.MensagemAtencao = "Número máximo de itens deste lote atigido! Tente alterar a quantidade de itens deste lote, ou crie um novo lote.";
                    }
                }
            }
            else
            {
                return(RedirectToAction("Home", "Home"));
            }
            ViewBag.Imagens = Usuario.ListarImagem(Session["NIF"]);
            return(View());
        }