Ejemplo n.º 1
0
        /// <summary>
        /// 更新按钮
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="incrementMenu"></param>
        /// <returns></returns>
        public async Task <bool> UpdateMenuAsync(UserCacheBo currentUser, IncrementMenuParam incrementMenu)
        {
            var count = await CurrentDbContext.SysMenus.Where(c => c.MenuId == incrementMenu.MenuId).UpdateFromQueryAsync(c => new SysMenu()
            {
                Deleted     = incrementMenu.Deleted,
                MenuName    = incrementMenu.MenuName,
                OrderIndex  = incrementMenu.OrderIndex,
                Icon        = incrementMenu.Icon,
                Url         = incrementMenu.Url,
                UpdatedBy   = currentUser.UserId,
                UpdatedTime = DateTime.Now,
            });

            return(count > 0);
            //var menu = await FindAsync<SysMenu>(incrementMenu.MenuId);
            //if (menu != null)
            //{
            //    menu.Deleted = incrementMenu.Deleted;
            //    menu.MenuName = incrementMenu.MenuName;
            //    menu.OrderIndex = incrementMenu.OrderIndex;
            //    menu.Icon = incrementMenu.Icon;
            //    menu.Url = incrementMenu.Url;
            //    menu.UpdatedBy = currentUser.UserId;
            //    menu.UpdatedTime = DateTime.Now;
            //    Update(menu);
            //}
            //return await SaveChangesAsync() > 0;
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> AddMenu(IncrementMenuParam incrementMenu)
        {
            var result = incrementMenu.IsUpdate
                ? await MenuBll.UpdateMenuAsync(CurrentUser, incrementMenu)
                : await MenuBll.AddMenuAsync(CurrentUser, incrementMenu);

            return(MyJson(result));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 修改菜单
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="incrementMenu"></param>
        /// <returns></returns>
        public async Task <BaseResponseModel> UpdateMenuAsync(UserCacheBo currentUser, IncrementMenuParam incrementMenu)
        {
            var responseModel = new ResponseModel <bool>();
            var count         = await SysMenuDao.UpdateMenuAsync(currentUser, incrementMenu);

            return(count ? responseModel.Succeed(true) : responseModel.Fail(ResponseCode.Fail, "修改失败"));
        }
Ejemplo n.º 4
0
        public virtual async Task <BaseResponseModel> AddMenuAsync(UserCacheBo currentUser, IncrementMenuParam incrementMenu)
        {
            var responseModel = new ResponseModel <bool>();
            var sysMenu       = incrementMenu.MapTo <SysMenu>();

            sysMenu.CreatedTime = DateTime.Now;
            sysMenu.CreatedBy   = currentUser.UserId;
            sysMenu.UpdatedBy   = currentUser.UserId;


            var relations = new List <SysRoleMenuRelation>();
            // 循环取出租户主体信息角色 增加新权限关系 默认为删除状态 点击分配给使用
            var db = SysMenuDao.CurrentDbContext;
            var roleIdsQueryable = db.SysUserRoleRelations.Where(c => !c.Deleted && c.State == 1 && c.TenantId > 1 && c.CreatedBy == 0).Select(c => new RoleCacheBo {
                RoleId = c.RoleId, TenantId = c.TenantId
            });

            for (int i = 1; i < 100000; i++)
            {
                var roleIds = SysMenuDao.LoadPageEntities(roleIdsQueryable, i, 100, true, roleId => roleId.RoleId);
                if (roleIds.PageData.Count > 0)
                {
                    roleIds.PageData.ForEach(roleInfo =>
                    {
                        relations.Add(new SysRoleMenuRelation()
                        {
                            TenantId    = roleInfo.TenantId,
                            MenuId      = sysMenu.MenuId,
                            RoleId      = roleInfo.RoleId,
                            Deleted     = true, //默认不分配给超级管理员看  需单独分配
                            CreatedTime = DateTime.Now,
                            CreatedBy   = 0,    //系统创建的都设置为0
                            State       = 1,
                        });
                    });
                }
                else
                {
                    break;
                }
            }

            relations.Add(new SysRoleMenuRelation()
            {
                TenantId    = 1,     //系统租户ID
                MenuId      = sysMenu.MenuId,
                RoleId      = 1,     //系统角色ID
                Deleted     = false, //系统管理员使用
                CreatedTime = DateTime.Now,
                CreatedBy   = 0,     //系统创建的都设置为0
                State       = 1,
            });

            await db.SysRoleMenuRelations.AddRangeAsync(relations);

            await SysMenuDao.AddAsync(sysMenu);

            var count = await SysMenuDao.SaveChangesAsync();

            return(count > 0 ? responseModel.Succeed(true) : responseModel.Fail(ResponseCode.Fail, "保存失败"));
        }