public ActionResult Create(int Id = 0, int consult = 0)
        {
            int ModuleId   = (Session["CurrentModuleId"] != null) ? Convert.ToInt32(Session["CurrentModuleId"]) : 0;
            var permission = PermissionHelper.GetRoleObjectPermission(SessionHelper.Role, 44729);

            ViewBag.Permission = permission;
            var varMS_Calorias = new MS_CaloriasModel();

            ViewBag.ObjectId  = "44729";
            ViewBag.Operation = "New";

            ViewBag.IsNew = true;



            if ((Id.GetType() == typeof(string) && Id.ToString() != "") || ((Id.GetType() == typeof(int) || Id.GetType() == typeof(Int16) || Id.GetType() == typeof(Int32) || Id.GetType() == typeof(Int64) || Id.GetType() == typeof(short)) && Id.ToString() != "0"))
            {
                ViewBag.IsNew     = false;
                ViewBag.Operation = "Update";
                if (!_tokenManager.GenerateToken())
                {
                    return(Json(null, JsonRequestBehavior.AllowGet));
                }
                _IMS_CaloriasApiConsumer.SetAuthHeader(_tokenManager.Token);
                var MS_CaloriasData = _IMS_CaloriasApiConsumer.GetByKeyComplete(Id).Resource.MS_Caloriass[0];
                if (MS_CaloriasData == null)
                {
                    return(HttpNotFound());
                }

                varMS_Calorias = new MS_CaloriasModel
                {
                    Folio              = (int)MS_CaloriasData.Folio
                    , Calorias         = MS_CaloriasData.Calorias
                    , CaloriasCantidad = CultureHelper.GetTraduction(Convert.ToString(MS_CaloriasData.Calorias), "Calorias") ?? (string)MS_CaloriasData.Calorias_Calorias.Cantidad
                };
            }
            if (!_tokenManager.GenerateToken())
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }

            _ICaloriasApiConsumer.SetAuthHeader(_tokenManager.Token);
            var Caloriass_Calorias = _ICaloriasApiConsumer.SelAll(true);

            if (Caloriass_Calorias != null && Caloriass_Calorias.Resource != null)
            {
                ViewBag.Caloriass_Calorias = Caloriass_Calorias.Resource.Where(m => m.Cantidad != null).OrderBy(m => m.Cantidad).Select(m => new SelectListItem
                {
                    Text = CultureHelper.GetTraduction(Convert.ToString(m.Clave), "Calorias", "Cantidad") ?? m.Cantidad.ToString(), Value = Convert.ToString(m.Clave)
                }).ToList();
            }


            ViewBag.Consult = consult == 1;
            if (consult == 1)
            {
                ViewBag.Operation = "Consult";
            }
            return(View(varMS_Calorias));
        }
Ejemplo n.º 2
0
        public ActionResult Create(int Id = 0, int consult = 0, int ModuleId = 0)
        {
            if (ModuleId == 0)
            {
                ModuleId = (Session["CurrentModuleId"] != null) ? Convert.ToInt32(Session["CurrentModuleId"]) : 0;
            }
            else
            {
                Session["CurrentModuleId"] = ModuleId;
            }
            var permission = PermissionHelper.GetRoleObjectPermission(SessionHelper.Role, 43965, ModuleId);

            if ((!permission.New && Id.ToString() == "0") || (!permission.Edit && Id.ToString() != "0" && (!permission.Consult && consult == 1)))
            {
                Response.Redirect("~/");
            }
            ViewBag.Permission = permission;
            var varCalorias = new CaloriasModel();

            varCalorias.Clave = Id;

            ViewBag.ObjectId  = "43965";
            ViewBag.Operation = "New";

            ViewBag.IsNew = true;



            if ((Id.GetType() == typeof(string) && Id.ToString() != "") || ((Id.GetType() == typeof(int) || Id.GetType() == typeof(Int16) || Id.GetType() == typeof(Int32) || Id.GetType() == typeof(Int64) || Id.GetType() == typeof(short)) && Id.ToString() != "0"))
            {
                ViewBag.IsNew     = false;
                ViewBag.Operation = "Update";

                _tokenManager.GenerateToken();
                _ISpartane_FileApiConsumer.SetAuthHeader(_tokenManager.Token);
                _ICaloriasApiConsumer.SetAuthHeader(_tokenManager.Token);
                var CaloriassData = _ICaloriasApiConsumer.ListaSelAll(0, 1000, "Calorias.Clave=" + Id, "").Resource.Caloriass;

                if (CaloriassData != null && CaloriassData.Count > 0)
                {
                    var CaloriasData = CaloriassData.First();
                    varCalorias = new CaloriasModel
                    {
                        Clave      = CaloriasData.Clave
                        , Cantidad = CaloriasData.Cantidad
                    };
                }
            }
            if (!_tokenManager.GenerateToken())
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }



            ViewBag.Consult = consult == 1;
            if (consult == 1)
            {
                ViewBag.Operation = "Consult";
            }

            var isPartial     = false;
            var isMR          = false;
            var nameMR        = string.Empty;
            var nameAttribute = string.Empty;

            if (Request.QueryString["isPartial"] != null)
            {
                isPartial = Convert.ToBoolean(Request.QueryString["isPartial"]);
            }

            if (Request.QueryString["isMR"] != null)
            {
                isMR = Convert.ToBoolean(Request.QueryString["isMR"]);
            }

            if (Request.QueryString["nameMR"] != null)
            {
                nameMR = Request.QueryString["nameMR"].ToString();
            }

            if (Request.QueryString["nameAttribute"] != null)
            {
                nameAttribute = Request.QueryString["nameAttribute"].ToString();
            }

            ViewBag.isPartial     = isPartial;
            ViewBag.isMR          = isMR;
            ViewBag.nameMR        = nameMR;
            ViewBag.nameAttribute = nameAttribute;


            return(View(varCalorias));
        }