Ejemplo n.º 1
0
        public MenuItemDTO AddMenuItem(Guid id, MenuItemDTO dto)
        {
            if (id == Guid.Empty)
                throw new ArgumentNullException("父菜单不能为空");
            if (string.IsNullOrEmpty(dto.Name))
                throw new ArgumentNullException("菜单名字不能为空");
            if (string.IsNullOrEmpty(dto.URL))
                throw new ArgumentNullException("菜单地址不能为空");
            if (dto.OrderIndex <= 0)
                throw new ArgumentNullException("菜单排序必须大于0");

            Menu menu = menuRepository.GetByKey(id);
            if (menu == null || menu.ID == Guid.Empty)
            {
                throw new ArgumentNullException("父菜单不存在");
            }

            MenuItem menuItem = Mapper.Map<MenuItemDTO, MenuItem>(dto);
            menu.AddMenuItem(menuItem);
            menuRepository.Update(menu);
            RepositoryContext.Commit();

            return Mapper.Map<MenuItem, MenuItemDTO>(menuItem);
        }
Ejemplo n.º 2
0
Archivo: DBTest.cs Proyecto: vebin/BDDD
        public void InitDBTest()
        {
            InitAppRuntime();

            ResetDB();

            IUserService userService = ServiceLocator.Instance.GetService<IUserService>();
            UserDTO user = new UserDTO()
                {
                    UserName = "******",
                    Password = "******",
                    DateLastLogin = DateTime.Now,
                    DateRegistered = DateTime.Now,
                    Email = "mail1",
                    IsDisabled = false,
                    NickName = "qlf1"
                };
            user = userService.AddUser(user);
            Assert.IsTrue(user.ID != Guid.Empty);

            IMenuService menuService = ServiceLocator.Instance.GetService<IMenuService>();
            MenuDTO userMenu = new MenuDTO
            {
                Name = "用户管理",
                Category = "AdminMenu",
                OrderIndex = 10
            };
            MenuDTO menu = new MenuDTO
            {
                Name = "菜单管理",
                Category = "AdminMenu",
                OrderIndex = 20
            };
            userMenu = menuService.AddMenu(userMenu);
            menu = menuService.AddMenu(menu);
            Assert.IsTrue(userMenu.ID != Guid.Empty);

            MenuItemDTO menuItem1 = new MenuItemDTO
            {
                Name = "用户管理",
                URL = "#",
                OrderIndex = 10
            };
            menuItem1 = menuService.AddMenuItem(userMenu.ID, menuItem1);

            MenuItemDTO menuItem2 = new MenuItemDTO
            {
                Name = "新增菜单",
                URL = "#",
                OrderIndex = 20
            };
            MenuItemDTO menuItem3 = new MenuItemDTO
            {
                Name = "菜单列表",
                URL = "/angularTemplates/admin/menulist.html",
                OrderIndex = 30
            };
            menuItem2 = menuService.AddMenuItem(menu.ID, menuItem2);
            menuItem3 = menuService.AddMenuItem(menu.ID, menuItem3);

            Assert.IsTrue(menuItem1.ID != Guid.Empty);
        }