Exemplo n.º 1
0
        public ActionResult AgregarMenu(AgregarMenuModel modelo, string btn_submit)
        {
            string date = Request.Form["__DATE"];
            bool _horario = false;
            if (modelo != null)
            {
                if (Request.Form["__HORARIO"] != null)
                {
                    if (Request.Form["__HORARIO"] == "True")
                        _horario = true;
                    else if (Request.Form["__HORARIO"] == "False")
                        _horario = false;
                }
                else
                {
                    _horario = modelo.horario;
                }
            }

            AgregarMenuModel new_model = new AgregarMenuModel();

            DateTime fecha = DateTime.Now.Date;

            if (fecha.DayOfWeek == DayOfWeek.Saturday)
                fecha = DateTime.Now.AddDays(2).Date;
            else if (fecha.DayOfWeek == DayOfWeek.Sunday)
                fecha = DateTime.Now.AddDays(1).Date;

            ViewBag.Fecha = fecha.ToString("dd-MM-yy");

            ViewBag.Horario = false.ToString();

            if (date != null)
            {
                ViewBag.Fecha = DateTime.Parse(date).ToString("dd-MM-yy");
                ViewBag.Horario = _horario;

                if (btn_submit != null)
                {
                    if (ModelState.IsValid)
                    {
                        LinqDBDataContext db = new LinqDBDataContext();
                        db.CrearFecha(DateTime.Parse(date), _horario);
                        int resp = new_model.setMenu(Int16.Parse(modelo.selected_item), short.Parse(modelo.selected_cant), DateTime.Parse(date), _horario);

                        if (resp == 2)
                        {
                            TempData.Add("Resp", "El Menu se ha actualizado");
                        }
                        else if (resp == 1)
                        {
                            TempData.Add("Resp", "Se ha agregado el ítem");
                        }
                        else if (resp == -1)
                        {
                            TempData.Add("Resp", "Ha ocurrido un error inesperado");
                        }

                        ModelState.Clear();
                    }
                }
                else
                {
                    ModelState.Clear();

                }
            }
            new_model.getListas();//DateTime.Parse(date)
            new_model.getMenu(DateTime.Parse(date), _horario);

            return View(new_model);
        }