Esempio n. 1
0
        public void Save_Ok()
        {
            var poco = new BootstrapMenu()
            {
                Name        = "UnitTest",
                Application = "0",
                Category    = "0",
                Icon        = "fa fa-fa",
                IsResource  = 0,
                Target      = "_blank",
                Order       = 10,
                Url         = "#",
                ParentId    = "0",
                ParentName  = "Test"
            };

            // insert
            Assert.True(MenuHelper.Save(poco));

            // update
            poco = MenuHelper.RetrieveAllMenus("Admin").Where(m => m.Id == poco.Id).FirstOrDefault();
            Assert.True(MenuHelper.Save(poco));

            // clean
            MenuHelper.Delete(new string[] { poco.Id });
        }
Esempio n. 2
0
        public void MenuDelete_Ok()
        {
            var menu = MenuHelper.RetrieveMenus("Admin").FirstOrDefault(m => m.Category == "0");

            Assert.True(MenuHelper.Delete(new string[] { menu.Id }));
            var menu2 = MenuHelper.RetrieveMenus("Admin").FirstOrDefault(m => m.Id == menu.Id);

            Assert.NotNull(menu2);

            // 保护模式下,正常選單可以刪除
            var poco = new BootstrapMenu()
            {
                Name        = "UnitTest",
                Application = "3",
                Category    = "1",
                Icon        = "fa fa-fa",
                IsResource  = 0,
                Target      = "_blank",
                Order       = 10,
                Url         = "#",
                ParentId    = "0",
                ParentName  = "Test",
            };

            // insert
            Assert.True(MenuHelper.Save(poco));

            // update
            poco = MenuHelper.RetrieveAllMenus("Admin").Where(m => m.Id == poco.Id).FirstOrDefault();
            Assert.True(MenuHelper.Save(poco));

            // clean
            MenuHelper.Delete(new string[] { poco.Id });
        }
Esempio n. 3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="menu"></param>
 public void Init(BootstrapMenu menu)
 {
     Title  = menu.Name;
     Url    = menu.Url.ToBlazorMenuUrl();
     Icon   = menu.Icon;
     Id     = menu.Id;
     Active = true;
 }
Esempio n. 4
0
        /// <summary>
        /// 保存選單
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public static bool Save(BootstrapMenu p)
        {
            // 不允許保存系統選單與前台演示系統的預設選單
            if (DictHelper.RetrieveSystemModel())
            {
                if (p.Category == "0")
                {
                    return(true);
                }

                // 查找原有資料比对是否為系統選單與演示選單
                if (!string.IsNullOrEmpty(p.Id))
                {
                    // 系統選單
                    var menus = RetrieveAllMenus("Admin");
#pragma warning disable CS8602 // 取消引用可能出现的空引用。
                    var menu = menus.FirstOrDefault(m => m.Id.Equals(p.Id, System.StringComparison.OrdinalIgnoreCase));
#pragma warning restore CS8602 // 取消引用可能出现的空引用。
                    if (menu != null && menu.Category == "0")
                    {
                        return(true);
                    }

                    // 演示系統
                    var appMenus = BootstrapAppContext.Configuration.GetSection("AppMenus").Get <ICollection <string> >();
                    if (appMenus.Any(m => m.Equals(menu?.Name, StringComparison.OrdinalIgnoreCase)))
                    {
                        return(true);
                    }
                }
            }

            var ret = DbContextManager.Create <Menu>()?.Save(p) ?? false;
            if (ret)
            {
                CacheCleanUtility.ClearCache(menuIds: string.IsNullOrEmpty(p.Id) ? new List <string>() : new List <string>()
                {
                    p.Id
                });
            }
            return(ret);
        }
Esempio n. 5
0
        /// <summary>
        /// 保存菜单
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public static bool Save(BootstrapMenu p)
        {
            // 不允许保存系统菜单与前台演示系统的默认菜单
            if (DictHelper.RetrieveSystemModel())
            {
                if (p.Category == "0")
                {
                    return(true);
                }

                // 查找原有数据比对是否为系统菜单与演示菜单
                if (!string.IsNullOrEmpty(p.Id))
                {
                    // 系统菜单
                    var menus = RetrieveAllMenus("Admin");
                    var menu  = menus.FirstOrDefault(m => m.Id.Equals(p.Id, System.StringComparison.OrdinalIgnoreCase));
                    if (menu != null && menu.Category == "0")
                    {
                        return(true);
                    }

                    // 演示系统
                    var appMenus = ConfigurationManager.GetSection("AppMenus").Get <ICollection <string> >();
                    if (appMenus.Any(m => m.Equals(menu.Name, System.StringComparison.OrdinalIgnoreCase)))
                    {
                        return(true);
                    }
                }
            }

            var ret = DbContextManager.Create <Menu>().Save(p);

            if (ret)
            {
                CacheCleanUtility.ClearCache(menuIds: string.IsNullOrEmpty(p.Id) ? new List <string>() : new List <string>()
                {
                    p.Id
                });
            }
            return(ret);
        }
Esempio n. 6
0
        /// <summary>
        /// 保存新建/更新的菜单信息
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public virtual bool Save(BootstrapMenu p)
        {
            if (string.IsNullOrEmpty(p.Name))
            {
                throw new ArgumentNullException(nameof(p.Name));
            }

            if (p.Name.Length > 50)
            {
                p.Name = p.Name.Substring(0, 50);
            }
            if (p.Icon != null && p.Icon.Length > 50)
            {
                p.Icon = p.Icon.Substring(0, 50);
            }
            if (p.Url != null && p.Url.Length > 4000)
            {
                p.Url = p.Url.Substring(0, 4000);
            }
            DbManager.Create().Save(p);
            return(true);
        }
Esempio n. 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public static bool Save(BootstrapMenu p)
        {
            // 不允许保存系统菜单与前台演示系统的默认菜单
            if (DictHelper.RetrieveSystemModel() && (p.Category == "0" || p.Application == "2"))
            {
                return(true);
            }

            if (p.Id == string.Empty)
            {
                p.Id = null;
            }
            var ret = DbContextManager.Create <Menu>().Save(p);

            if (ret)
            {
                CacheCleanUtility.ClearCache(menuIds: string.IsNullOrEmpty(p.Id) ? new List <string>() : new List <string>()
                {
                    p.Id
                });
            }
            return(ret);
        }
Esempio n. 8
0
        public void Save_EmptyId()
        {
            var poco = new BootstrapMenu()
            {
                Id          = "",
                Name        = "UnitTest",
                Application = "0",
                Category    = "0",
                Icon        = "fa fa-fa",
                IsResource  = 0,
                Target      = "_blank",
                Order       = 10,
                Url         = "#",
                ParentId    = "0",
                ParentName  = "Test"
            };

            // insert
            Assert.True(MenuHelper.Save(poco));

            // clean
            MenuHelper.Delete(new string[] { poco.Id });
        }
Esempio n. 9
0
        /// <summary>
        /// 添加 Tab 由侧边栏菜单调用
        /// </summary>
        /// <param name="menu"></param>
        public void AddTab(BootstrapMenu menu)
        {
            var tab = Tabs.FirstOrDefault(tb => tb.Id == menu.Id);

            if (tab == null)
            {
                tab = new Tab();
                tab.Init(menu);
                Tabs.ForEach(t => t.SetActive(false));
                Tabs.Add(tab);
                Pages.ForEach(p => p.Active = false);
                Pages.Add(new PageContentAttributes()
                {
                    Id = menu.Id, Name = menu.Url, Active = true
                });
            }
            else
            {
                Tabs.ForEach(t => t.SetActive(t.Id == tab.Id));
                Pages.ForEach(p => p.Active = p.Id == tab.Id);
            }
            curId = tab.Id;
            StateHasChanged();
        }
Esempio n. 10
0
        /// <summary>
        /// 保存菜单
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public override bool Save(BootstrapMenu p)
        {
            if (string.IsNullOrEmpty(p.Id))
            {
                p.Id = null;
                DbManager.Menus.InsertOne(p);
                p.Id = DbManager.Menus.Find(m => m.Name == p.Name && m.Category == p.Category && m.ParentId == p.ParentId && m.Url == p.Url).FirstOrDefault().Id;
            }
            else
            {
                var update = Builders <BootstrapMenu> .Update.Set(md => md.ParentId, p.ParentId)
                             .Set(md => md.Name, p.Name)
                             .Set(md => md.Order, p.Order)
                             .Set(md => md.Icon, p.Icon)
                             .Set(md => md.Url, p.Url)
                             .Set(md => md.Category, p.Category)
                             .Set(md => md.Target, p.Target)
                             .Set(md => md.IsResource, p.IsResource)
                             .Set(md => md.Application, p.Application);

                DbManager.Menus.UpdateOne(md => md.Id == p.Id, update);
            }
            return(true);
        }
Esempio n. 11
0
 public bool Post([FromBody] BootstrapMenu value)
 {
     return(MenuHelper.Save(value));
 }