Ejemplo n.º 1
0
        public async Task<IResultModel> BindMenu(RoleMenuBindModel model)
        {
            var exists = await _repository.ExistsAsync(model.Id);
            if (!exists)
                return ResultModel.NotExists;

            List<RoleMenuEntity> entityList = null;
            if (model.Menus != null && model.Menus.Any())
            {
                entityList = model.Menus.Select(m => new RoleMenuEntity { RoleId = model.Id, MenuId = m }).ToList();
            }

            /*
             * 操作逻辑
             * 1、清除已有的绑定数据
             * 2、添加新的绑定数据
             */
            using (var uow = _dbContext.NewUnitOfWork())
            {
                var clear = await _roleMenuRepository.DeleteByRoleId(model.Id, uow);
                if (clear)
                {
                    if (entityList == null || !entityList.Any() || await _roleMenuRepository.AddAsync(entityList, uow))
                    {
                        uow.Commit();
                        await ClearAccountPermissionCache(model.Id);
                        return ResultModel.Success();
                    }
                }
            }

            return ResultModel.Failed();
        }
Ejemplo n.º 2
0
        public async Task <IResultModel> BindMenus(RoleMenuBindModel model)
        {
            if (!await _repository.ExistsAsync(model.RoleId))
            {
                return(ResultModel.NotExists);
            }

            using var uow = _dbContext.NewUnitOfWork();

            if (await _roleMenuRepository.DeleteByRoleId(model.RoleId, uow))
            {
                if (model.Menus != null && model.Menus.Any())
                {
                    var menus = model.Menus
                                .Where(menuId => menuId.NotEmpty())
                                .Select(menuId => new RoleMenuEntity
                    {
                        RoleId = model.RoleId,
                        MenuId = menuId
                    }).ToList();
                    await _roleMenuRepository.AddAsync(menus, uow);
                }

                uow.Commit();

                //清楚缓存
                await ClearAccountPermissionCache(model.RoleId);

                return(ResultModel.Success());
            }

            return(ResultModel.Failed());
        }
Ejemplo n.º 3
0
        public async Task <IResultModel> BindMenu(RoleMenuBindModel model)
        {
            var exists = await _repository.ExistsAsync(model.Id);

            if (!exists)
            {
                return(ResultModel.NotExists);
            }

            List <RoleMenu> entityList = null;

            if (model.Menus != null && model.Menus.Any())
            {
                entityList = model.Menus.Select(m => new RoleMenu {
                    RoleId = model.Id, MenuId = m
                }).ToList();
            }

            /*
             * 操作逻辑
             * 1、清除已有的绑定数据
             * 2、添加新的绑定数据
             */
            _uow.BeginTransaction();

            var clear = await _roleMenuRepository.DeleteByRoleId(model.Id);

            if (clear)
            {
                if (entityList == null || !entityList.Any() || await _roleMenuRepository.AddAsync(entityList))
                {
                    _uow.Commit();

                    await ClearAccountPermissionCache(model.Id);

                    return(ResultModel.Success());
                }
            }

            _uow.Rollback();
            return(ResultModel.Failed());
        }
Ejemplo n.º 4
0
 public Task <IResultModel> BindMenu(RoleMenuBindModel model)
 {
     return(_service.BindMenu(model));
 }