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, 133);

            ViewBag.Permission = permission;
            var varSpartan_WorkFlow_Roles_by_State = new Spartan_WorkFlow_Roles_by_StateModel();

            ViewBag.ObjectId  = "133";
            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_Roles_by_StateApiConsumer.SetAuthHeader(_tokenManager.Token);
                var Spartan_WorkFlow_Roles_by_StateData = _ISpartan_WorkFlow_Roles_by_StateApiConsumer.GetByKeyComplete(Id).Resource.Spartan_WorkFlow_Roles_by_States[0];
                if (Spartan_WorkFlow_Roles_by_StateData == null)
                {
                    return(HttpNotFound());
                }

                varSpartan_WorkFlow_Roles_by_State = new Spartan_WorkFlow_Roles_by_StateModel
                {
                    Roles_by_StateId        = (int)Spartan_WorkFlow_Roles_by_StateData.Roles_by_StateId
                    , Phase                 = Spartan_WorkFlow_Roles_by_StateData.Phase
                    , PhaseName             = (string)Spartan_WorkFlow_Roles_by_StateData.Phase_Spartan_WorkFlow_Phases.Name
                    , State                 = Spartan_WorkFlow_Roles_by_StateData.State
                    , StateName             = (string)Spartan_WorkFlow_Roles_by_StateData.State_Spartan_WorkFlow_State.Name
                    , User_Role             = Spartan_WorkFlow_Roles_by_StateData.User_Role
                    , Phase_Transition      = Spartan_WorkFlow_Roles_by_StateData.Phase_Transition
                    , Permission_To_Consult = Spartan_WorkFlow_Roles_by_StateData.Permission_To_Consult.GetValueOrDefault()
                    , Permission_To_New     = Spartan_WorkFlow_Roles_by_StateData.Permission_To_New.GetValueOrDefault()
                    , Permission_To_Modify  = Spartan_WorkFlow_Roles_by_StateData.Permission_To_Modify.GetValueOrDefault()
                    , Permission_to_Delete  = Spartan_WorkFlow_Roles_by_StateData.Permission_to_Delete.GetValueOrDefault()
                    , Permission_To_Export  = Spartan_WorkFlow_Roles_by_StateData.Permission_To_Export.GetValueOrDefault()
                    , Permission_To_Print   = Spartan_WorkFlow_Roles_by_StateData.Permission_To_Print.GetValueOrDefault()
                    , Permission_Settings   = Spartan_WorkFlow_Roles_by_StateData.Permission_Settings.GetValueOrDefault()
                };
            }
            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();
            }


            ViewBag.Consult = consult == 1;
            if (consult == 1)
            {
                ViewBag.Operation = "Consult";
            }
            return(View(varSpartan_WorkFlow_Roles_by_State));
        }
Beispiel #2
0
        /// <summary>
        /// Used to get the Permission for Role Object
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="objectId"></param>
        /// <returns></returns>
        public static Permission GetRoleObjectPermission(int roleId, int objectId = 0, int moduleId = 0, int attributeId = 0)
        {
            try
            {
                if (!_tokenManager.GenerateToken("admin", "admin"))
                {
                    throw new ArgumentException("Unable to Authorize the application");
                }

                if (objectId == 0 && attributeId != 0)
                {
                    _ISpartan_MetadataApiConsumer.SetAuthHeader(_tokenManager.Token);
                    var resultMeta = _ISpartan_MetadataApiConsumer.GetByKey(attributeId, false).Resource;
                    objectId = Convert.ToInt32(resultMeta.Related_Object_Id);
                    moduleId = 0;
                }


                _spartaneUserRoleObjectFunctionApiConsumer.SetAuthHeader(_tokenManager.Token);
                _spartaneFunctionApiConsumer.SetAuthHeader(_tokenManager.Token);
                string where = "spartan_user_rule_object_function.Object_Id=" + objectId +
                               " AND spartan_user_rule_object_function.Spartan_User_Rule=" + roleId;
                if (moduleId != 0)
                {
                    where += " AND spartan_user_rule_object_function.Module_Id=" + moduleId;
                }
                var userRoleObjectFunctions = _spartaneUserRoleObjectFunctionApiConsumer.ListaSelAll(1, int.MaxValue, where, "").Resource;

                if (userRoleObjectFunctions == null ||
                    userRoleObjectFunctions.Spartan_User_Rule_Object_Functions == null)
                {
                    return(new Permission());
                }

                var spartaneFuctions = new List <SpartaneFunction>();

                foreach (var userRoleObjectFunction in userRoleObjectFunctions.Spartan_User_Rule_Object_Functions)
                {
                    spartaneFuctions.Add(_spartaneFunctionApiConsumer.GetByKey(userRoleObjectFunction.Fuction_Id, true).Resource);
                }

                Permission ObjectPermissions = GetSpartanePermission(spartaneFuctions);
                //WorkFlows Permissions
                #region WorkFlows Permissions
                if (System.Web.HttpContext.Current.Session != null)
                {
                    if (System.Web.HttpContext.Current.Session["Phase"] != null)
                    {
                        if (System.Web.HttpContext.Current.Session["Phase"].ToString() != "")
                        {
                            //Consult if the object has workflow assigned
                            _Spartan_WorkFlowApiConsumer.SetAuthHeader(_tokenManager.Token);
                            var workflowObject = _Spartan_WorkFlowApiConsumer.ListaSelAll(1, int.MaxValue, "spartan_workflow.object = " + objectId.ToString() + " and spartan_workflow.status=1", "").Resource;
                            if (workflowObject != null)
                            {
                                if (workflowObject.Spartan_WorkFlows.Count != 0)
                                {
                                    //Consultar id de Fase
                                    _Spartan_WorkFlow_PhasesApiConsumer.SetAuthHeader(_tokenManager.Token);
                                    var phaseObject = _Spartan_WorkFlow_PhasesApiConsumer.ListaSelAll(1, int.MaxValue, "Spartan_WorkFlow_Phases.WorkFlow=" + workflowObject.Spartan_WorkFlows[0].WorkFlowId.ToString() + " and Spartan_WorkFlow_Phases.Phase_Number=" + System.Web.HttpContext.Current.Session["Phase"].ToString() + " and Spartan_WorkFlow_Phases.phase_status=1", "").Resource;
                                    if (phaseObject != null)
                                    {
                                        if (phaseObject.Spartan_WorkFlow_Phasess.Count != 0)
                                        {
                                            //Consultar Permisos
                                            _Spartan_WorkFlow_Roles_by_StateApiConsumer.SetAuthHeader(_tokenManager.Token);
                                            var rolesObject = _Spartan_WorkFlow_Roles_by_StateApiConsumer.ListaSelAll(1, int.MaxValue, "Spartan_WorkFlow_Roles_by_State.Spartan_WorkFlow=" + workflowObject.Spartan_WorkFlows[0].WorkFlowId.ToString() + " and Spartan_WorkFlow_Roles_by_State.Phase=" + phaseObject.Spartan_WorkFlow_Phasess[0].PhasesId.ToString() + " and Spartan_WorkFlow_Roles_by_State.User_Role=" + roleId.ToString(), "").Resource;
                                            if (rolesObject != null)
                                            {
                                                if (rolesObject.Spartan_WorkFlow_Roles_by_States.Count != 0)
                                                {
                                                    if (rolesObject.Spartan_WorkFlow_Roles_by_States[0].Permission_To_New == false)
                                                    {
                                                        ObjectPermissions.New = false;
                                                    }

                                                    if (rolesObject.Spartan_WorkFlow_Roles_by_States[0].Permission_To_Modify == false)
                                                    {
                                                        ObjectPermissions.Edit = false;
                                                    }

                                                    if (rolesObject.Spartan_WorkFlow_Roles_by_States[0].Permission_to_Delete == false)
                                                    {
                                                        ObjectPermissions.Delete = false;
                                                    }

                                                    if (rolesObject.Spartan_WorkFlow_Roles_by_States[0].Permission_To_Export == false)
                                                    {
                                                        ObjectPermissions.Export = false;
                                                    }

                                                    if (rolesObject.Spartan_WorkFlow_Roles_by_States[0].Permission_To_Print == false)
                                                    {
                                                        ObjectPermissions.Print = false;
                                                    }

                                                    if (rolesObject.Spartan_WorkFlow_Roles_by_States[0].Permission_Settings == false)
                                                    {
                                                        ObjectPermissions.Configure = false;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                #endregion
                return(ObjectPermissions);
            }
            catch (ArgumentException)
            {
                return(new Permission());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }