public ActionResult Create(short Id = 0, int consult = 0)
        {
            var permission = PermissionHelper.GetRoleObjectPermission(SessionHelper.Role, 130);

            ViewBag.Permission = permission;
            var varSpartan_WorkFlow_Condition = new Spartan_WorkFlow_ConditionModel();

            ViewBag.ObjectId  = "130";
            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));
                }
                _ISpartan_WorkFlow_ConditionApiConsumer.SetAuthHeader(_tokenManager.Token);
                var Spartan_WorkFlow_ConditionData = _ISpartan_WorkFlow_ConditionApiConsumer.GetByKeyComplete(Id).Resource.Spartan_WorkFlow_Conditions[0];
                if (Spartan_WorkFlow_ConditionData == null)
                {
                    return(HttpNotFound());
                }

                varSpartan_WorkFlow_Condition = new Spartan_WorkFlow_ConditionModel
                {
                    ConditionId   = (short)Spartan_WorkFlow_ConditionData.ConditionId
                    , Description = Spartan_WorkFlow_ConditionData.Description
                };
            }
            if (!_tokenManager.GenerateToken())
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }



            ViewBag.Consult = consult == 1;
            if (consult == 1)
            {
                ViewBag.Operation = "Consult";
            }
            return(View(varSpartan_WorkFlow_Condition));
        }
        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, 128);

            ViewBag.Permission = permission;
            var varSpartan_WorkFlow_Conditions_by_State = new Spartan_WorkFlow_Conditions_by_StateModel();

            ViewBag.ObjectId  = "128";
            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));
                }
                _ISpartan_WorkFlow_Conditions_by_StateApiConsumer.SetAuthHeader(_tokenManager.Token);
                var Spartan_WorkFlow_Conditions_by_StateData = _ISpartan_WorkFlow_Conditions_by_StateApiConsumer.GetByKeyComplete(Id).Resource.Spartan_WorkFlow_Conditions_by_States[0];
                if (Spartan_WorkFlow_Conditions_by_StateData == null)
                {
                    return(HttpNotFound());
                }

                varSpartan_WorkFlow_Conditions_by_State = new Spartan_WorkFlow_Conditions_by_StateModel
                {
                    Conditions_by_StateId = (int)Spartan_WorkFlow_Conditions_by_StateData.Conditions_by_StateId
                    , Phase                         = Spartan_WorkFlow_Conditions_by_StateData.Phase
                    , PhaseName                     = (string)Spartan_WorkFlow_Conditions_by_StateData.Phase_Spartan_WorkFlow_Phases.Name
                    , State                         = Spartan_WorkFlow_Conditions_by_StateData.State
                    , StateName                     = (string)Spartan_WorkFlow_Conditions_by_StateData.State_Spartan_WorkFlow_State.Name
                    , Condition_Operator            = Spartan_WorkFlow_Conditions_by_StateData.Condition_Operator
                    , Condition_OperatorDescription = (string)Spartan_WorkFlow_Conditions_by_StateData.Condition_Operator_Spartan_WorkFlow_Condition_Operator.Description
                    , Attribute                     = Spartan_WorkFlow_Conditions_by_StateData.Attribute
                    , AttributeLogical_Name         = (string)Spartan_WorkFlow_Conditions_by_StateData.Attribute_Spartan_Metadata.Logical_Name
                    , Condition                     = Spartan_WorkFlow_Conditions_by_StateData.Condition
                    , ConditionDescription          = (string)Spartan_WorkFlow_Conditions_by_StateData.Condition_Spartan_WorkFlow_Condition.Description
                    , Operator                      = Spartan_WorkFlow_Conditions_by_StateData.Operator
                    , OperatorDescription           = (string)Spartan_WorkFlow_Conditions_by_StateData.Operator_Spartan_WorkFlow_Operator.Description
                    , Operator_Value                = Spartan_WorkFlow_Conditions_by_StateData.Operator_Value
                    , Priority                      = Spartan_WorkFlow_Conditions_by_StateData.Priority
                };
            }
            if (!_tokenManager.GenerateToken())
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }

            _ISpartan_WorkFlow_PhasesApiConsumer.SetAuthHeader(_tokenManager.Token);
            var Spartan_WorkFlow_Phasess_Phase = _ISpartan_WorkFlow_PhasesApiConsumer.SelAll(true);

            if (Spartan_WorkFlow_Phasess_Phase != null && Spartan_WorkFlow_Phasess_Phase.Resource != null)
            {
                ViewBag.Spartan_WorkFlow_Phasess_Phase = Spartan_WorkFlow_Phasess_Phase.Resource.OrderBy(m => m.Name).Select(m => new SelectListItem
                {
                    Text = m.Name.ToString(), Value = Convert.ToString(m.PhasesId)
                }).ToList();
            }
            _ISpartan_WorkFlow_StateApiConsumer.SetAuthHeader(_tokenManager.Token);
            var Spartan_WorkFlow_States_State = _ISpartan_WorkFlow_StateApiConsumer.SelAll(true);

            if (Spartan_WorkFlow_States_State != null && Spartan_WorkFlow_States_State.Resource != null)
            {
                ViewBag.Spartan_WorkFlow_States_State = Spartan_WorkFlow_States_State.Resource.OrderBy(m => m.Name).Select(m => new SelectListItem
                {
                    Text = m.Name.ToString(), Value = Convert.ToString(m.StateId)
                }).ToList();
            }
            _ISpartan_WorkFlow_Condition_OperatorApiConsumer.SetAuthHeader(_tokenManager.Token);
            var Spartan_WorkFlow_Condition_Operators_Condition_Operator = _ISpartan_WorkFlow_Condition_OperatorApiConsumer.SelAll(true);

            if (Spartan_WorkFlow_Condition_Operators_Condition_Operator != null && Spartan_WorkFlow_Condition_Operators_Condition_Operator.Resource != null)
            {
                ViewBag.Spartan_WorkFlow_Condition_Operators_Condition_Operator = Spartan_WorkFlow_Condition_Operators_Condition_Operator.Resource.OrderBy(m => m.Description).Select(m => new SelectListItem
                {
                    Text = m.Description.ToString(), Value = Convert.ToString(m.Condition_OperatorId)
                }).ToList();
            }
            _ISpartan_MetadataApiConsumer.SetAuthHeader(_tokenManager.Token);
            var Spartan_Metadatas_Attribute = _ISpartan_MetadataApiConsumer.SelAll(true);

            if (Spartan_Metadatas_Attribute != null && Spartan_Metadatas_Attribute.Resource != null)
            {
                ViewBag.Spartan_Metadatas_Attribute = Spartan_Metadatas_Attribute.Resource.OrderBy(m => m.Logical_Name).Select(m => new SelectListItem
                {
                    Text = m.Logical_Name.ToString(), Value = Convert.ToString(m.AttributeId)
                }).ToList();
            }
            _ISpartan_WorkFlow_ConditionApiConsumer.SetAuthHeader(_tokenManager.Token);
            var Spartan_WorkFlow_Conditions_Condition = _ISpartan_WorkFlow_ConditionApiConsumer.SelAll(true);

            if (Spartan_WorkFlow_Conditions_Condition != null && Spartan_WorkFlow_Conditions_Condition.Resource != null)
            {
                ViewBag.Spartan_WorkFlow_Conditions_Condition = Spartan_WorkFlow_Conditions_Condition.Resource.OrderBy(m => m.Description).Select(m => new SelectListItem
                {
                    Text = m.Description.ToString(), Value = Convert.ToString(m.ConditionId)
                }).ToList();
            }
            _ISpartan_WorkFlow_OperatorApiConsumer.SetAuthHeader(_tokenManager.Token);
            var Spartan_WorkFlow_Operators_Operator = _ISpartan_WorkFlow_OperatorApiConsumer.SelAll(true);

            if (Spartan_WorkFlow_Operators_Operator != null && Spartan_WorkFlow_Operators_Operator.Resource != null)
            {
                ViewBag.Spartan_WorkFlow_Operators_Operator = Spartan_WorkFlow_Operators_Operator.Resource.OrderBy(m => m.Description).Select(m => new SelectListItem
                {
                    Text = m.Description.ToString(), Value = Convert.ToString(m.OperatorId)
                }).ToList();
            }


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