public List <string> GetRolesByControllerAction(ControllerAction controllerAction)
        {
            List <string> roles = new List <string>();

            if (controllerAction != null)
            {
                roles = controllerAction.MVCAuthorizations.Select(r => r.aspnet_Roles.RoleName).Distinct().ToList();
            }

            return(roles);
        }
        public List<string> GetRolesByControllerAction(ControllerAction controllerAction)
        {
            List<string> roles = new List<string>();

            if (controllerAction != null)
            {
                roles = controllerAction.MVCAuthorizations.Select(r => r.aspnet_Roles.RoleName).Distinct().ToList();
            }

            return roles;
        }
        public void UpdateActionList()
        {
            DB.ControllerActions.ToList();

            List <Type> typeList = Assembly.GetExecutingAssembly().GetExportedTypes().Where(r => r.HasBaseType(typeof(Controller))).ToList();


            //Delete non-existing controllers
            foreach (var item in typeList)
            {
                ReflectedControllerDescriptor controllerDes = new ReflectedControllerDescriptor(item);
                string controllerName = controllerDes.ControllerName;

                ControllerAction controllerOfActionAuthorization = DB.ControllerActions.Where(r => r.Controller == controllerName &&
                                                                                              string.IsNullOrEmpty(r.Action) &&
                                                                                              string.IsNullOrEmpty(r.HttpVerb)
                                                                                              ).FirstOrDefault();

                if (controllerOfActionAuthorization == null)
                {
                    controllerOfActionAuthorization            = new ControllerAction();
                    controllerOfActionAuthorization.Controller = controllerName;
                    DB.AddToControllerActions(controllerOfActionAuthorization);
                    Save();
                }

                List <ActionDescriptor> actionDescriptorList = controllerDes.GetCanonicalActions().ToList();

                foreach (var actionDesc in actionDescriptorList)
                {
                    string parameters = string.Join(", ", actionDesc.GetParameters().Select(r => r.ParameterName));

                    string httpVerb = actionDesc.GetHttpVerb();

                    string actionName = actionDesc.ActionName;

                    ControllerAction actionOfActionAuthorization = DB.ControllerActions.Where(r => r.Controller == controllerName && r.Action == actionName && r.HttpVerb == httpVerb).FirstOrDefault();
                    if (actionOfActionAuthorization == null)
                    {
                        actionOfActionAuthorization            = new ControllerAction();
                        actionOfActionAuthorization.Controller = controllerName;
                        actionOfActionAuthorization.Action     = actionName;
                        actionOfActionAuthorization.Parameters = parameters;
                        actionOfActionAuthorization.HttpVerb   = httpVerb;

                        DB.AddToControllerActions(actionOfActionAuthorization);
                        Save();
                    }
                }
            }
        }
        public void UpdateActionList()
        {
            DB.ControllerActions.ToList();

            List<Type> typeList = Assembly.GetExecutingAssembly().GetExportedTypes().Where(r => r.HasBaseType(typeof(Controller))).ToList();

            //Delete non-existing controllers
            foreach (var item in typeList)
            {
                ReflectedControllerDescriptor controllerDes = new ReflectedControllerDescriptor(item);
                string controllerName = controllerDes.ControllerName;

                ControllerAction controllerOfActionAuthorization = DB.ControllerActions.Where(r => r.Controller == controllerName
                    && string.IsNullOrEmpty(r.Action)
                    && string.IsNullOrEmpty(r.HttpVerb)
                    ).FirstOrDefault();

                if (controllerOfActionAuthorization == null)
                {
                    controllerOfActionAuthorization = new ControllerAction();
                    controllerOfActionAuthorization.Controller = controllerName;
                    DB.AddToControllerActions(controllerOfActionAuthorization);
                    Save();
                }

                List<ActionDescriptor> actionDescriptorList = controllerDes.GetCanonicalActions().ToList();

                foreach (var actionDesc in actionDescriptorList)
                {
                    string parameters = string.Join(", ", actionDesc.GetParameters().Select(r => r.ParameterName));

                    string httpVerb = actionDesc.GetHttpVerb();

                    string actionName = actionDesc.ActionName;

                    ControllerAction actionOfActionAuthorization = DB.ControllerActions.Where(r => r.Controller == controllerName && r.Action == actionName && r.HttpVerb == httpVerb).FirstOrDefault();
                    if (actionOfActionAuthorization == null)
                    {
                        actionOfActionAuthorization = new ControllerAction();
                        actionOfActionAuthorization.Controller = controllerName;
                        actionOfActionAuthorization.Action = actionName;
                        actionOfActionAuthorization.Parameters = parameters;
                        actionOfActionAuthorization.HttpVerb = httpVerb;

                        DB.AddToControllerActions(actionOfActionAuthorization);
                        Save();
                    }
                }
            }
        }
        public List <string> GetRolesByActionDescriptor(ActionDescriptor actionDescriptor)
        {
            List <string> roles = new List <string>();

            if (actionDescriptor != null)
            {
                ControllerActionRepository controllerActionRepository = new ControllerActionRepository();

                ControllerAction controllerAction = controllerActionRepository.Get(actionDescriptor);

                roles = GetRolesByControllerAction(controllerAction);
            }

            return(roles);
        }
Esempio n. 6
0
 /// <summary>
 /// Deprecated Method for adding a new object to the ControllerActions EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToControllerActions(ControllerAction controllerAction)
 {
     base.AddObject("ControllerActions", controllerAction);
 }
Esempio n. 7
0
 /// <summary>
 /// Create a new ControllerAction object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 public static ControllerAction CreateControllerAction(global::System.Int32 id)
 {
     ControllerAction controllerAction = new ControllerAction();
     controllerAction.ID = id;
     return controllerAction;
 }