public void AddPrivilege(List <Guid> menuids) { var admin = DC.Set <FrameworkRole>().Where(x => x.RoleCode == "001").FirstOrDefault(); if (admin != null && SelectedRolesIds.Contains(admin.ID) == false) { SelectedRolesIds.Add(admin.ID); } var codes = DC.Set <FrameworkRole>().Where(x => SelectedRolesIds.Contains(x.ID)).Select(x => x.RoleCode).ToList(); foreach (var menuid in menuids) { if (SelectedRolesIds != null) { foreach (var code in codes) { FunctionPrivilege fp = new FunctionPrivilege(); fp.MenuItemId = menuid; fp.RoleCode = code; fp.Allowed = true; DC.Set <FunctionPrivilege>().Add(fp); } } } DC.SaveChanges(); }
protected override void InitVM() { if (!string.IsNullOrEmpty(Entity.Icon)) { var res = Entity.Icon.Split(' '); IconFont = res[0]; IconFontItem = res[1]; } SelectedRolesIds.AddRange(DC.Set <FunctionPrivilege>().Where(x => x.MenuItemId == Entity.ID && x.RoleCode != null && x.Allowed == true).Select(x => x.ID).ToList()); var data = DC.Set <FrameworkMenu>().AsNoTracking().ToList(); var topMenu = data.Where(x => x.ParentId == null).ToList().FlatTree(x => x.DisplayOrder); var pids = Entity.GetAllChildrenIDs(DC); AllParents = data.Where(x => x.ID != Entity.ID && !pids.Contains(x.ID) && x.FolderOnly == true).ToList().ToListItems(y => y.PageName, x => x.ID); foreach (var p in AllParents) { if (p.Text.StartsWith("MenuKey.")) { p.Text = Localizer[p.Text]; } } var modules = Wtm.GlobaInfo.AllModule; var toRemove = new List <SimpleModule>(); foreach (var item in modules) { if (item.IgnorePrivillege) { toRemove.Add(item); } } var m = modules.ToList(); toRemove.ForEach(x => m.Remove(x)); AllModules = m.ToListItems(y => y.ModuleName, y => y.FullName); if (string.IsNullOrEmpty(SelectedModule) == false || (string.IsNullOrEmpty(Entity.Url) == false && Entity.IsInside == true)) { if (string.IsNullOrEmpty(SelectedModule)) { SelectedModule = modules.Where(x => (x.FullName == Entity.ClassName)).FirstOrDefault()?.FullName; } var mm = modules.Where(x => x.FullName == SelectedModule).SelectMany(x => x.Actions).Where(x => x.MethodName != "Index" && x.IgnorePrivillege == false).ToList(); AllActions = mm.ToListItems(y => y.ActionName, y => y.Url); if (SelectedActionIDs == null) { SelectedActionIDs = DC.Set <FrameworkMenu>().Where(x => AllActions.Select(y => y.Value).Contains(x.Url) && x.IsInside == true && x.FolderOnly == false).Select(x => x.Url).ToList(); } } }