public DashboardControllerAttributeModel( DashboardControllerAttribute parentControllerAttribute , List <DashboardControllerAttributeModel> childrenControllerAttributes , IEnumerable <DashboardActionAttribute> actionAttributes) { ParentControllerAttribute = parentControllerAttribute; ChildrenControllerAttributes = childrenControllerAttributes; ChildrenActionAttributes = actionAttributes; }
private static List <DashboardActionAttribute> GetActionAttributes( DashboardControllerAttribute dashboardControllerAttribute) { //if(dashboardControllerAttribute.ParentControllerType == DashboardControllerType.Null) // return new List<DashboardActionAttribute>(); var controllers = DashboardControllers(); var dashboardControllerName = (dashboardControllerAttribute.Name + "Controller").ToLower(); var actionAttributes = controllers .FirstOrDefault(x => x.Name.ToLower() == dashboardControllerName).GetMethods() .Where(x => x.IsPublic && x.ReturnType == typeof(ActionResult) && x.GetCustomAttributes() .Any()).ToList() .SelectMany(x => x.GetCustomAttributes <DashboardActionAttribute>() .Select(y => new DashboardActionAttribute(y, DashboardAreaRegistration.GetAreaName .AddSlashBetweenWords(x.DeclaringType.Name.RemoveWordFromString("Controller") .AddSlashBetweenWords(x.Name), true)))).ToList(); //MODULE PERMISSIONS var modulePermissionService = DependencyResolver.Current.GetService <IModulePermissionService>(); var applicationRoleManager = DependencyResolver.Current.GetService <ApplicationRoleManager>(); if (HttpContext.Current.User != null) { IIdentity identity = HttpContext.Current.User.Identity; var userId = Int32.Parse(identity.GetUserId()); var roleIds = applicationRoleManager.Roles .Where(x => x.Users.Select(y => y.UserId) .Contains(userId)).Select(x => x.Id).ToList(); var permittedModules = modulePermissionService.Entities.Include(x => x.Module) .Where(x => (x.UserId == userId || roleIds.Contains(x.RoleId.Value)) && x.Permission != Permissions.None) .Select(x => x.Module.ModuleName).ToList(); if (permittedModules != null && permittedModules.Any()) { actionAttributes.Where(x => permittedModules.Contains(x.Name)).ToList(); } else { return(new List <DashboardActionAttribute>()); } } return(actionAttributes); }