Ejemplo n.º 1
0
 public ResponseModel Delete(Menu menu)
 {
     return _menuRepository.Delete(menu);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Update permissions for menu
        /// </summary>
        /// <param name="menu"></param>
        private void UpdateMenuPermission(Menu menu)
        {
            var permissions = new List<PermissionEnums>();
            if (string.IsNullOrEmpty(menu.Controller))
            {
                menu.Permissions = string.Empty;
            }
            else
            {
                var assemblies = AppDomain.CurrentDomain.GetAssemblies(); // currently loaded assemblies
                var controllerType = assemblies
                    .SelectMany(a => a.GetTypes())
                    .FirstOrDefault(t => t != null
                        && t.IsPublic
                        && t.Name.Equals(string.Format("{0}Controller", menu.Controller), StringComparison.OrdinalIgnoreCase)
                        && !t.IsAbstract
                        && typeof(IController).IsAssignableFrom(t));
                if (controllerType != null)
                {

                    //Get permission from controller
                    var controllerAuthorizationAttributes = controllerType.GetCustomAttributes(typeof(PxAuthorizeAttribute), false)
                                    .Cast<PxAuthorizeAttribute>();
                    foreach (var attribute in controllerAuthorizationAttributes)
                    {
                        if (attribute.Permissions != null && attribute.Permissions.Any())
                            permissions.AddRange(attribute.Permissions);
                    }

                    //Get permission from actions
                    var methods = controllerType.GetMethods(BindingFlags.Public | BindingFlags.Instance)
                        .Where(m => typeof(ActionResult).IsAssignableFrom(m.ReturnType)
                                    && m.Name.Equals(menu.Action)).ToList();
                    if (methods.Any())
                    {
                        foreach (var methodInfo in methods)
                        {
                            var actionAuthorizationAttributes = methodInfo
                                    .GetCustomAttributes(typeof(PxAuthorizeAttribute), false)
                                    .Cast<PxAuthorizeAttribute>();
                            foreach (var attribute in actionAuthorizationAttributes)
                            {
                                permissions.AddRange(attribute.Permissions);
                            }
                        }
                    }
                }
            }
            menu.Permissions = permissions.Any() ? string.Join(",", permissions.Select(i => (int)i)) : string.Empty;
            Update(menu);
        }
Ejemplo n.º 3
0
 public ResponseModel Update(Menu menu)
 {
     return _menuRepository.Update(menu);
 }
Ejemplo n.º 4
0
 public ResponseModel Insert(Menu menu)
 {
     return _menuRepository.Insert(menu);
 }
Ejemplo n.º 5
0
 public ResponseModel HierarchyUpdate(Menu menu)
 {
     return _menuRepository.HierarchyUpdate(menu);
 }
Ejemplo n.º 6
0
 public ResponseModel HierarchyInsert(Menu menu)
 {
     return _menuRepository.HierarchyInsert(menu);
 }