/// <summary>
        /// 删除
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Result <int> deleteSecondlevelDir(int id)
        {
            Result <int> result = new Result <int>();

            try
            {
                using (var ts = new TransactionScope())
                {
                    DirDbContext      context     = new DirDbContext();
                    RoleMenuDbContext roleContext = new RoleMenuDbContext();
                    var entity = context.secondLevels.Where(x => x.id == id).FirstOrDefault();
                    if (entity != null)
                    {
                        context.secondLevels.Remove(entity);
                        context.SaveChanges();
                    }
                    var roleMenu = roleContext.roleMenus.Where(x => x.menuLevel == 2 && x.menuId == id).FirstOrDefault();
                    if (roleMenu != null)
                    {
                        roleContext.roleMenus.Remove(roleMenu);
                        roleContext.SaveChanges();
                    }
                    ts.Complete();
                }
            }
            catch (Exception err)
            {
                result.addError(err.Message);
            }
            return(result);
        }
Exemplo n.º 2
0
        public async Task <RoleMenu> searchRoleMenuById(int id)
        {
            RoleMenuDbContext roleMenuDB = new RoleMenuDbContext();
            RoleMenu          model      = await roleMenuDB.roleMenus.FindAsync(id);

            return(model);
        }
Exemplo n.º 3
0
        /// <summary>
        /// delete by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <Result <RoleMenu> > deleteMenuAsync(int id)
        {
            Result <RoleMenu> result = new Result <RoleMenu>();

            try
            {
                RoleMenuDbContext context = new RoleMenuDbContext();
                RoleMenu          model   = await context.roleMenus.FindAsync(id);

                context.roleMenus.Remove(model);
                int count = await context.SaveChangesAsync();

                if (count == 0)
                {
                    result.success = false;
                    result.message = "This Role Do Not Include This Menu";
                }
            }
            catch (Exception err)
            {
                result.success = false;
                result.message = err.Message;
            }
            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 根据roleId查询角色权限
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List <RoleMenu> searchRoleMenus(string id = null)
        {
            RoleMenuDbContext roleMenuDB = new RoleMenuDbContext();

            if (string.IsNullOrEmpty(id))
            {
                return(roleMenuDB.roleMenus.ToList());
            }
            else
            {
                return(roleMenuDB.roleMenus.Where(x => x.roleId == id).ToList());
            }
        }
        public string searchMainDir(string roleId)
        {
            DirDbContext      dirContext  = new DirDbContext();
            RoleMenuDbContext roleContext = new RoleMenuDbContext();
            var           menuIds         = roleContext.roleMenus.Where(x => x.roleId == roleId && x.menuLevel == 1).Select(x => x.menuId).ToArray();
            var           mainDir         = dirContext.firstLevels.Where(x => menuIds.Contains(x.id) && x.activityFlag == 1).OrderBy(x => x.orderId).ToList();
            StringBuilder htmlStr         = new StringBuilder("");

            foreach (var item in mainDir)
            {
                htmlStr.Append(item.beforContent).Append(item.midContent).Append(item.afterContent);
            }
            return(htmlStr.ToString());
        }
Exemplo n.º 6
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int deleteFirstlevelDir(int id)
        {
            //DONE: delete from roleMenu
            DirDbContext context = new DirDbContext();
            var          result  = context.firstLevels.Where(x => x.id > 0 && x.id == id);
            FirstLevel   entity  = result.First();

            context.firstLevels.Remove(entity);

            RoleMenuDbContext roleContext = new RoleMenuDbContext();
            var roleMenu = roleContext.roleMenus.Where(x => x.menuLevel == 1 && x.menuId == id).First();

            roleContext.roleMenus.Remove(roleMenu);
            roleContext.SaveChanges();
            return(context.SaveChanges());
        }
Exemplo n.º 7
0
        /// <summary>
        /// add range async
        /// </summary>
        /// <param name="menuList"></param>
        /// <returns></returns>
        public async Task <Result <RoleMenu> > addRoleMenuRangeAsync(List <RoleMenu> menuList)
        {
            Result <RoleMenu> result = new Result <RoleMenu>();

            try
            {
                RoleMenuDbContext roleMenuDB = new RoleMenuDbContext();
                roleMenuDB.roleMenus.AddRange(menuList);
                int count = await roleMenuDB.SaveChangesAsync();
            }
            catch (Exception err)
            {
                result.success = false;
                result.message = err.Message;
            }
            return(result);
        }
        public List <Menu> searchSecondDir(string roleId, int ID)
        {
            DirDbContext      dirContext  = new DirDbContext();
            RoleMenuDbContext roleContext = new RoleMenuDbContext();
            var         menuIds           = roleContext.roleMenus.Where(x => x.roleId == roleId && x.menuLevel == 2).Select(x => x.menuId).ToArray();
            var         secondDirs        = dirContext.secondLevels.Where(x => x.firstLevelId == ID && menuIds.Contains(x.id) && x.activityFlag == 1).OrderBy(x => x.orderId).ToList();
            List <Menu> result            = new List <Menu>();
            Menu        model             = null;

            foreach (var item in secondDirs)
            {
                model       = new Menu();
                model.Id    = item.id;
                model.open  = item.open;
                model.title = item.title;
                model.url   = item.url;
                result.Add(model);
            }
            return(result);
        }