Ejemplo n.º 1
0
        /******************************************************************** CADASTRAR LOTE ********************************************************************/
        public ActionResult CadastrarLote()
        {
            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"))
                {
                    try
                    {
                        DateTime     Hora         = DateTime.UtcNow;
                        TimeZoneInfo NossaZona    = TimeZoneInfo.FindSystemTimeZoneById("E. South America Standard Time");
                        DateTime     Databrasilia = TimeZoneInfo.ConvertTimeFromUtc(Hora, NossaZona);

                        L.NomeLote        = Request.Form["nomeLote"].ToString();
                        L.DataEntrada     = Databrasilia;
                        L.DataValidade    = Convert.ToDateTime(Request.Form["dataValidade"].ToString());
                        L.Quantidadeitens = Convert.ToInt32(Request.Form["quantidadeitens"].ToString());

                        if (L.DataValidade > L.DataEntrada)
                        {
                            L.CadastrarLote(Session["NIF"].ToString());


                            /***** CHAMA ESSE METODO PARA DESCOBRIR QUAL E O CODIGO DO LOTE PARA PODER ATRIBUIR O CODIGO NA VARIAVEL 'CodigoLote'
                             * PODENDO CADASTRAR UM INGREDIENTE A PARTIR DO LINK DIRETO DE 'CADASTRAR UM LOTE' *****/
                            L.SelecionaLote(L.NomeLote);
                            Session["NomeLote"] = L.NomeLote;
                            Session["Mensagem"] = ViewBag.MensagemSucesso = "Cadastro realizado com sucesso!";

                            Response.Redirect("/Ingrediente/CadastrarIngrediente/" + L.CodigoLote, false);
                        }
                        else
                        {
                            ViewBag.MensagemAtencao = "Data de validade não pode ser menor que a data de entrada.";
                        }
                    }
                    catch
                    {
                        ViewBag.MensagemErro = "Campo(s) preenchido(s) incorretamente! Verifique todos os campos.";
                    }
                }
            }
            else
            {
                return(RedirectToAction("Home", "Home"));
            }
            ViewBag.Imagens = Usuario.ListarImagem(Session["NIF"]);
            return(View());
        }
Ejemplo n.º 2
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());
        }