예제 #1
0
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> Edit(int id, [Bind("ModuleMenuId,ModuleMenuName,ModuleMenuCaption,ModuleMenuImage,ImagePath,ModuleImageExtension,ModuleMenuController,ModuleMenuLink,IsInActive,IsParent,Active,SLNO,ModuleId,ModuleGroupId,ImageCriteriaId,ParentId")] ModuleMenu moduleMenu)
        {
            if (id != moduleMenu.ModuleMenuId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(moduleMenu);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ModuleMenuExists(moduleMenu.ModuleMenuId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ImageCriteriaId"] = new SelectList(_context.ImageCriterias, "ImageCriteriaId", "ImageCriteriaCaption", moduleMenu.ImageCriteriaId);
            ViewData["ModuleGroupId"]   = new SelectList(_context.ModuleGroups, "ModuleGroupId", "ModuleGroupName", moduleMenu.ModuleGroupId);
            ViewData["ModuleId"]        = new SelectList(_context.Modules, "ModuleId", "ModuleName", moduleMenu.ModuleId);
            return(View(moduleMenu));
        }
예제 #2
0
        public bool AddMenu(string menuName, string menuCode, int menuType, int parentId, string url, bool isPage, bool isEnable, bool isVisible)
        {
            if (_moduleMenuRepository.GetFilter(it => it.MenuName.Equals(menuName) || it.MenuCode.Equals(menuCode)).Count() > 0)
            {
                throw new CustomException(Constant.REPEATED_MENU);
            }
            if (menuType < 0)
            {
                throw new CustomException(Constant.ERRORPARAM_MENU);
            }
            ModuleMenu mm = new ModuleMenu()
            {
                CreateDateTime = DateTime.Now,
                IsDeleted      = false,
                IsEnable       = isEnable,
                IsPage         = isPage,
                IsVisible      = isVisible,
                MenuCode       = menuCode,
                MenuName       = menuName,
                MenuType       = (MenuType)menuType,
                URL            = url
            };

            if (parentId > 0)
            {
                mm.ParentId = parentId;
            }
            _moduleMenuRepository.Add(mm);
            _unitOfWork.Commit();
            return(true);
        }
예제 #3
0
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> Create(ModuleMenu moduleMenu, string imageDatatest)
        {
            var errors = ModelState.Where(x => x.Value.Errors.Any())
                         .Select(x => new { x.Key, x.Value.Errors });

            if (ModelState.IsValid)
            {
                if (moduleMenu.ModuleMenuId > 0)
                {
                    _context.Entry(moduleMenu).State = EntityState.Modified;
                    _context.SaveChanges();
                }
                else
                {
                    if (moduleMenu.ParentId == -1)
                    {
                        moduleMenu.ParentId = 0;
                    }
                    var error = ModelState.Where(x => x.Value.Errors.Any())
                                .Select(x => new { x.Key, x.Value.Errors });
                    _context.Add(moduleMenu);
                    await _context.SaveChangesAsync();

                    _context.Entry(moduleMenu).GetDatabaseValues();
                    int id = moduleMenu.ModuleMenuId;
                    return(RedirectToAction(nameof(Index)));
                }
            }
            ViewData["ImageCriteriaId"] = new SelectList(_context.ImageCriterias, "ImageCriteriaId", "ImageCriteriaCaption", moduleMenu.ImageCriteriaId);
            ViewData["ModuleGroupId"]   = new SelectList(_context.ModuleGroups, "ModuleGroupId", "ModuleGroupName", moduleMenu.ModuleGroupId);
            ViewData["ModuleId"]        = new SelectList(_context.Modules, "ModuleId", "ModuleName", moduleMenu.ModuleId);
            return(View(moduleMenu));
        }
예제 #4
0
        private MenuItem GetModuleMenuItem(string moduleName, ControllerContext controllerContext, ControllerContext moduleControllerContext)
        {
            MenuItem moduleMenuItem = new MenuItem()
            {
                Text = moduleName, Action = "", Controller = "", HtmlAttributes = new System.Web.Routing.RouteValueDictionary(), RouteValues = new System.Web.Routing.RouteValueDictionary()
            };
            var moduleMenu = ModuleMenu.GetModuleMenu(moduleName, controllerContext, moduleControllerContext, new RouteValueDictionary(new { area = "Sites" }), Site.Current.FullName, "Module", "Scaffold");

            moduleMenuItem.Items = moduleMenu.Items;
            return(moduleMenuItem);
        }
예제 #5
0
        private void AddMenuToList(List <ModuleMenu> list, ModuleMenu item)
        {
            if (!ValidateMenu(item))
            {
                return;
            }

            if (item.Directly.HasValue && !item.Directly.Value)
            {
                // 避免无意义的序列化
                item.Directly = null;
            }

            if (item.Type == ModuleMenuType.Item && !item.Children.IsNullOrEmpty())
            {
                throw new Exception("菜单项【{0}】不能包含子项".FormatWith(item.Title));
            }
            if (item.Type == ModuleMenuType.Sub || item.Type == ModuleMenuType.Group)
            {
                if (!item.LinkRouteName.IsNullOrWhiteSpace())
                {
                    throw new Exception("{0}【{1}】不能设置路由".FormatWith(item.Type == ModuleMenuType.Sub ? "子菜单" : "菜单组", item.Title));
                }
                if (item.Directly.HasValue && item.Directly.Value)
                {
                    throw new Exception("{0}【{1}】不能设置为直接访问".FormatWith(item.Type == ModuleMenuType.Sub ? "子菜单" : "菜单组", item.Title));
                }

                if (item.Children.IsNullOrEmpty())
                {
                    // 如果类型是 Sub 或 Group 并且没有任何 Child,则本菜单也不用显示。
                    return;
                }

                var newChildren = new List <ModuleMenu>();
                item.Children.ForEach(m => AddMenuToList(newChildren, m));
                if (newChildren.IsNullOrEmpty())
                {
                    // 如果经过全选过滤,子菜单或菜单组已无子项,则本子菜单或菜单组也不用显示。
                    return;
                }
                item.Children = newChildren;
            }

            if (item.Type == ModuleMenuType.Item && ValidateMenu(item))
            {
                item.Link = Url.RouteUrl(item.LinkRouteName, item.LinkRouteValues);
            }
            list.Add(item);
        }
예제 #6
0
        public void InitView()
        {
            MenuBarType view = View.PreloadView;

            if (view == MenuBarType.None)
            {
                view = MenuBarType.GenericCommunity;
            }

            if (UserContext.isAnonymous)
            {
                View.DisplaySessionTimeout(rootObject.MenuBarList(view));
            }
            else
            {
                Boolean            allowManage = false;
                ModuleMenu         module      = ModuleMenu.CreatePortalmodule(UserContext.UserTypeID);
                List <MenuBarType> views       = GetAvailableViews(module);
                if (views.Count == 0)
                {
                    View.NoPermission();
                }
                else
                {
                    if (!views.Contains(view))
                    {
                        view = views[0];
                    }
                    View.LoadAvailableViews(views);
                    View.CurrentView = view;

                    switch (view)
                    {
                    case MenuBarType.Portal:
                        allowManage = module.ManagePortalMenubar;
                        break;

                    case MenuBarType.GenericCommunity:
                        allowManage = module.ManageCommunitiesMenubar;
                        break;

                    case MenuBarType.PortalAdministration:
                        allowManage = module.ManageAdministrationMenubar;
                        break;
                    }
                    View.AllowCreate = allowManage;
                    LoadMenubarItems(module, view, 0, View.CurrentPageSize);
                }
            }
        }
예제 #7
0
        private bool ValidateMenu(ModuleMenu item)
        {
            if (item.Permission.IsNullOrWhiteSpace() && item.Role.IsNullOrWhiteSpace() && item.Group.IsNullOrWhiteSpace() && item.Validator == null)
            {
                return(true);
            }

            var user = HttpContext.User;

            if (item.Validator != null)
            {
                return(item.Validator(user));
            }

            if (item.Permission != null)
            {
                var perArray = item.Permission.Split('|', ';', ',');
                foreach (var it in perArray)
                {
                    if (user.HasPermission(it))
                    {
                        return(true);
                    }
                }
            }
            if (item.Role != null)
            {
                var rolArray = item.Role.Split('|', ';', ',');
                foreach (var it in rolArray)
                {
                    if (HttpContext.User.IsInRole(it))
                    {
                        return(true);
                    }
                }
            }
            if (item.Group != null)
            {
                var grpArray = item.Group.Split('|', ';', ',');
                foreach (var it in grpArray)
                {
                    if (user.IsInGroup(it))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
예제 #8
0
        public void InitView()
        {
            MenuBarType view = View.PreloadType;

            if (view == MenuBarType.None)
            {
                view = MenuBarType.GenericCommunity;
            }

            if (UserContext.isAnonymous)
            {
                View.DisplaySessionTimeout(rootObject.CreateMenuBar(view));
            }
            else
            {
                Boolean            allowManage = false;
                ModuleMenu         module      = ModuleMenu.CreatePortalmodule(UserContext.UserTypeID);
                List <MenuBarType> views       = GetAvailableViews(module);
                if (views.Count == 0)
                {
                    View.NoPermission();
                }
                else
                {
                    if (!views.Contains(view))
                    {
                        view = views[0];
                    }
                    View.LoadAvailableTypes(views);

                    allowManage      = module.ManagePortalMenubar || module.ManageAdministrationMenubar || module.ManageCommunitiesMenubar;
                    View.AllowCreate = allowManage;
                    if (allowManage)
                    {
                        View.TopItemsnumber = 5;
                        View.SubItemsnumber = 5;
                        dtoMenubar dto = new dtoMenubar();
                        dto.MenuBarType = view;
                        dto.Name        = View.DefaultMenuName;
                        View.MenuBar    = dto;
                    }
                    else
                    {
                        View.NoPermission();
                    }
                }
            }
        }
예제 #9
0
        private List <MenuBarType> GetAvailableViews(ModuleMenu module)
        {
            List <MenuBarType> views = new List <MenuBarType>();

            if (module.ManagePortalMenubar)
            {
                views.Add(MenuBarType.Portal);
            }
            if (module.ManageAdministrationMenubar)
            {
                views.Add(MenuBarType.PortalAdministration);
            }
            if (module.ManageCommunitiesMenubar)
            {
                views.Add(MenuBarType.GenericCommunity);
            }
            return(views);
        }
예제 #10
0
        // Protected Methods (1) 

        protected override void OnHandleInput(string input,
                                              ref IMenuHandler nextHandler,
                                              ref bool isValid)
        {
            switch (input)
            {
            case "1":
                nextHandler = new ModuleMenu();
                break;

            case "x":
                nextHandler = null;
                break;

            default:
                isValid = false;
                break;
            }
        }
예제 #11
0
        private void LoadMenubarItems(ModuleMenu module, MenuBarType view, int currentPageIndex, int currentPageSize)
        {
            int       itemsCount = (int)Service.GetMenubarListCount(view);
            PagerBase pager      = new PagerBase();

            pager.PageSize  = currentPageSize;  //Me.View.CurrentPageSize
            pager.Count     = itemsCount - 1;
            pager.PageIndex = currentPageIndex; // Me.View.CurrentPageIndex
            View.Pager      = pager;

            if (itemsCount == 0)
            {
                View.LoadItems(new List <dtoMenubarItemPermission>());
            }
            else
            {
                List <dtoMenubar> items = Service.GetMenubarList(view, pager.PageIndex, currentPageSize);
                View.LoadItems(items.Select(m => new dtoMenubarItemPermission(m, module)).ToList());
            }
        }
예제 #12
0
 public void SetActiveMenubar(long idMenubar)
 {
     if (UserContext.isAnonymous)
     {
         View.DisplaySessionTimeout(rootObject.MenuBarList(View.CurrentView));
     }
     else
     {
         ModuleMenu  module      = ModuleMenu.CreatePortalmodule(UserContext.UserTypeID);
         MenuBarType view        = View.CurrentView;
         Boolean     allowManage = (view == MenuBarType.PortalAdministration) ? module.ManagePortalMenubar : (view == MenuBarType.GenericCommunity) ? module.ManageCommunitiesMenubar : (view == MenuBarType.Portal) ? module.ManageAdministrationMenubar : false;
         if (allowManage && Service.SetActiveMenubar(idMenubar))
         {
             View.ReloadPage(idMenubar, view, View.Pager.PageIndex, View.CurrentPageSize);
         }
         else
         {
             LoadMenubarItems(View.Pager.PageIndex, View.CurrentPageSize);
         }
     }
 }
예제 #13
0
        public dtoMenubarItemPermission(dtoMenubar menubar, ModuleMenu module)
        {
            dtoMenubarPermission permission = new dtoMenubarPermission();
            Boolean AllowManage             = ((module.ManagePortalMenubar && menubar.MenuBarType == MenuBarType.Portal) ||
                                               (module.ManageAdministrationMenubar && menubar.MenuBarType == MenuBarType.PortalAdministration) ||
                                               (module.ManageCommunitiesMenubar && menubar.MenuBarType == MenuBarType.GenericCommunity));
            Boolean AllowSetActive = ((module.SetActivePortalMenubar && menubar.MenuBarType == MenuBarType.Portal) ||
                                      (module.SetActiveAdministrationMenubar && menubar.MenuBarType == MenuBarType.PortalAdministration) ||
                                      (module.SetActiveCommunitiesMenubar && menubar.MenuBarType == MenuBarType.GenericCommunity));

            if (AllowManage)
            {
                permission.AddItem         = AllowManage;
                permission.Delete          = (menubar.Deleted != Core.DomainModel.BaseStatusDeleted.None);
                permission.VirtualDelete   = (menubar.Deleted == Core.DomainModel.BaseStatusDeleted.None && !menubar.IsCurrent);
                permission.VirtualUndelete = (menubar.Deleted != Core.DomainModel.BaseStatusDeleted.None);
                permission.Edit            = AllowManage;
                permission.SetActive       = (AllowManage && AllowSetActive && (menubar.Deleted == Core.DomainModel.BaseStatusDeleted.None));
            }
            this.MenuBar    = menubar;
            this.Permission = permission;
        }
예제 #14
0
        public void InitView()
        {
            MenuBarType view = View.PreviousView;

            if (UserContext.isAnonymous)
            {
                View.DisplaySessionTimeout(rootObject.EditMenuBar(View.PreloadIdMenubar, view));
            }
            else
            {
                ModuleMenu module      = ModuleMenu.CreatePortalmodule(UserContext.UserTypeID);
                Boolean    allowManage = module.ManagePortalMenubar || module.ManageAdministrationMenubar || module.ManageCommunitiesMenubar;
                View.AllowManage = allowManage;
                if (!allowManage)
                {
                    View.NoPermission();
                }
                else
                {
                    long IdMenubar = View.PreloadIdMenubar;
                    if (!Service.MenubarExist(IdMenubar))
                    {
                        View.MenubarUnknown();
                    }
                    else
                    {
                        View.IdMenubar = IdMenubar;
                        View.AllowEdit = !Service.IsActiveMenubar(IdMenubar);
                        dtoTree tree = Service.MenubarToTree(IdMenubar);
                        View.LoadMenubar(tree, new dtoItem()
                        {
                            Id = tree.Id, Type = MenuItemType.Menubar
                        });
                        View.LoadMenuBarInfo(Service.GetDtoMenubar(tree.Id));
                    }
                }
            }
        }
예제 #15
0
 public void EditActiveMenubar(long idMenubar, String menuBarName)
 {
     if (UserContext.isAnonymous)
     {
         View.DisplaySessionTimeout(rootObject.MenuBarList(View.CurrentView));
     }
     else
     {
         dtoMenubar dto = Service.GetDtoMenubar(idMenubar);
         if (dto != null)
         {
             ModuleMenu module      = ModuleMenu.CreatePortalmodule(UserContext.UserTypeID);
             Boolean    allowManage = (dto.MenuBarType == MenuBarType.PortalAdministration) ? module.ManagePortalMenubar : (dto.MenuBarType == MenuBarType.GenericCommunity) ? module.ManageCommunitiesMenubar : (dto.MenuBarType == MenuBarType.Portal) ? module.ManageAdministrationMenubar : false;
             if (allowManage)
             {
                 Menubar clone = Service.CloneMenubar(idMenubar, (menuBarName.Contains("{0}")) ? String.Format(menuBarName, dto.Name) : "[COPY] " + dto.Name);
                 if (clone != null)
                 {
                     View.EditMenubar(clone.Id, clone.MenuBarType);
                 }
             }
         }
     }
 }
예제 #16
0
        public async Task <ModuleMenu> Create(ModuleMenu menu)
        {
            await _moduleMenuRepository.CreateSync(menu);

            return(menu);
        }
예제 #17
0
        public void LoadMenubarItems(int currentPageIndex, int currentPageSize)
        {
            ModuleMenu module = ModuleMenu.CreatePortalmodule(UserContext.UserTypeID);

            LoadMenubarItems(module, View.CurrentView, currentPageIndex, currentPageSize);
        }
예제 #18
0
파일: SysService.cs 프로젝트: phonia/BBS
        public void InitDataBase()
        {
            if (_webConfigRepository.GetFilter(it => it.IsInitialed == true).FirstOrDefault() != null)
            {
                return;
            }
            _webConfigRepository.Add(new WebConfig()
            {
                IsInitialed = true
            });

            #region 领域服务
            Type[] types = Assembly.GetExecutingAssembly().GetTypes();
            if (types != null && types.Count() > 0)
            {
                foreach (var service in types)
                {
                    if (service.GetInterfaces().Contains(typeof(IDomainService)))
                    {
                        //TODO
                        Service s = new Service()
                        {
                            Assembly = Assembly.GetExecutingAssembly().FullName,
                            FullName = service.FullName
                        };
                        MethodInfo[] methodInfos = service.GetMethods();
                        if (methodInfos != null && methodInfos.Count() > 0)
                        {
                            foreach (var type in methodInfos)
                            {
                                ServiceMethod sm = new ServiceMethod()
                                {
                                    Name = type.Name
                                };
                                if (s.Methods == null)
                                {
                                    s.Methods = new List <ServiceMethod>();
                                }
                                s.Methods.Add(sm);
                            }
                        }
                        _serviceRepository.Add(s);
                    }
                }
            }
            #endregion

            #region 用户、角色

            UserGroup ug1 = new UserGroup()
            {
                Name = Constant.DEFAULT_USERGROUP
            };
            Role r1 = new Role()
            {
                Name = Constant.ANONYMOUS_ROLE, RoleType = RoleType.UnKnown
            };
            Role r2 = new Role()
            {
                Name = Constant.MANAGER_ROLE, RoleType = RoleType.SysBuiltIn
            };
            User u1 = new User()
            {
                AccountName     = Constant.SUPERMANAGER_USER,
                AccountPassword = Constant.SUPERMANAGER_USER,
                Role            = r2,
                AccountInfo     = new AccountInfo()
                {
                    LoginCount = 0, LoginDate = DateTime.Today, LoginIP = "192.168.5.108", RegisterDate = DateTime.Today, RegisterIp = "192.168.5.108"
                },
                UserGroup    = ug1,
                PersonalInfo = new PersonalInfo()
                {
                    Age = 28, Email = "*****@*****.**", Fax = "34510996", Name = "HY", Phone = "15975455335", Sex = Sex.Male, Tel = "87072280"
                }
            };

            User u2 = new User()
            {
                AccountName     = Constant.SUPERMANAGER_USER,
                AccountPassword = Constant.SUPERMANAGER_USER,
                Role            = r1,
                AccountInfo     = new AccountInfo()
                {
                    LoginCount = 0, LoginDate = DateTime.Today, LoginIP = "192.168.5.108", RegisterDate = DateTime.Today, RegisterIp = "192.168.5.108"
                },
                UserGroup    = ug1,
                PersonalInfo = new PersonalInfo()
                {
                    Age = 28, Email = "*****@*****.**", Fax = "34510996", Name = "POLAN", Phone = "15975455335", Sex = Sex.Male, Tel = "87072280"
                }
            };
            _userRepository.Add(u1);
            _userRepository.Add(u2);

            #endregion

            #region 预置目录

            ModuleMenu mm1 = new ModuleMenu()
            {
                IsEnable       = true,
                CreateDateTime = DateTime.Now,
                IsDeleted      = false,
                IsPage         = false,
                IsVisible      = true,
                MenuCode       = "ModuleMenu",
                MenuName       = "系统设置",
                URL            = "/Home/GetBackStageSecondaryMenu",
                MenuType       = MenuType.BackStage,
                Children       = new List <ModuleMenu>()
                {
                    new ModuleMenu()
                    {
                        IsEnable       = true,
                        CreateDateTime = DateTime.Now,
                        IsDeleted      = false,
                        IsPage         = false,
                        IsVisible      = true,
                        MenuCode       = "MenuSetting",
                        MenuName       = "目录设置",
                        MenuType       = MenuType.BackStage,
                        URL            = "/Menu/EditMenu"
                    }
                }
            };

            //ModuleMenu mm1 = new ModuleMenu()
            //{
            //    IsEnable = true,
            //    Children = new List<ModuleMenu>() {
            //        new ModuleMenu()
            //        {
            //            IsEnable=true
            //        }
            //    }
            //};
            this._moduleMenuRepository.Add(mm1);

            #endregion

            _unitOfWork.Commit();
        }