Beispiel #1
0
        public async Task <MessageModel <string> > Assign([FromBody] AssignView assignView)
        {
            var data = new MessageModel <string>();


            if (assignView.rid > 0)
            {
                data.success = true;

                var roleModulePermissions = await _roleModulePermissionServices.Query(d => d.RoleId == assignView.rid);

                var remove = roleModulePermissions.Where(d => !assignView.pids.Contains(d.PermissionId.ObjToInt())).Select(c => (object)c.Id);
                data.success &= remove.Any() ? await _roleModulePermissionServices.DeleteByIds(remove.ToArray()) : true;

                foreach (var item in assignView.pids)
                {
                    var rmpitem  = roleModulePermissions.Where(d => d.PermissionId == item);
                    var moduleid = (await _permissionServices.Query(p => p.Id == item)).FirstOrDefault()?.Mid;
                    if (!rmpitem.Any())
                    {
                        RoleModulePermission roleModulePermission = new RoleModulePermission()
                        {
                            IsDeleted    = false,
                            RoleId       = assignView.rid,
                            ModuleId     = moduleid.ObjToInt(),
                            PermissionId = item,
                        };


                        roleModulePermission.CreateId = _user.ID;
                        roleModulePermission.CreateBy = _user.Name;

                        data.success &= (await _roleModulePermissionServices.Add(roleModulePermission)) > 0;
                    }
                    else
                    {
                        foreach (var role in rmpitem)
                        {
                            if (!role.ModuleId.Equals(moduleid))
                            {
                                role.ModuleId = moduleid.Value;
                                await _roleModulePermissionServices.Update(role, new List <string> {
                                    "ModuleId"
                                });
                            }
                        }
                    }
                }

                if (data.success)
                {
                    _requirement.Permissions.Clear();
                    data.response = "";
                    data.msg      = "保存成功";
                }
            }


            return(data);
        }
        public async Task <MessageModel <string> > Assign([FromBody] AssignView assignView)
        {
            var data = new MessageModel <string>();

            try
            {
                if (assignView.rid > 0)
                {
                    data.success = true;

                    var roleModulePermissions = await _roleModulePermissionServices.Query(d => d.RoleId == assignView.rid);

                    var remove = roleModulePermissions.Where(d => !assignView.pids.Contains(d.PermissionId.ObjToInt())).Select(c => (object)c.Id);
                    data.success |= await _roleModulePermissionServices.DeleteByIds(remove.ToArray());

                    foreach (var item in assignView.pids)
                    {
                        var rmpitem = roleModulePermissions.Where(d => d.PermissionId == item);
                        if (!rmpitem.Any())
                        {
                            var moduleid = (await _permissionServices.Query(p => p.Id == item)).FirstOrDefault()?.Mid;
                            RoleModulePermission roleModulePermission = new RoleModulePermission()
                            {
                                IsDeleted    = false,
                                RoleId       = assignView.rid,
                                ModuleId     = moduleid.ObjToInt(),
                                PermissionId = item,
                            };


                            roleModulePermission.CreateId = _user.ID;
                            roleModulePermission.CreateBy = _user.Name;

                            data.success |= (await _roleModulePermissionServices.Add(roleModulePermission)) > 0;
                        }
                    }

                    if (data.success)
                    {
                        data.response = "";
                        data.msg      = "保存成功";
                    }
                }
            }
            catch (Exception)
            {
                data.success = false;
            }

            return(data);
        }
        public async Task <MessageModel <ResponseEnum> > Get()
        {
            var data = new MessageModel <ResponseEnum>();

            var i = 0;
            var d = 3 / i;

            var blogArticles = await _blogArticleServices.GetBlogs();

            var roleModulePermissions = await _roleModulePermissionServices.QueryMuchTable();

            var roleModuleTask = _roleModulePermissionServices.Query();
            var listTask       = _advertisementServices.Query();

            var ad   = await roleModuleTask;
            var list = await listTask;


            _advertisementServices.ReturnExp();

            Love love = null;

            love.SayLoveU();

            return(data);
        }
        public async Task <MessageModel <ResponseEnum> > Get()
        {
            var data = new MessageModel <ResponseEnum>();



            // 测试模拟异常,全局异常过滤器拦截
            var i = 0;
            var d = 3 / i;



            // 测试多表联查
            var roleModulePermissions = await _roleModulePermissionServices.QueryMuchTable();


            // 测试多个异步执行时间
            var roleModuleTask = _roleModulePermissionServices.Query();
            var listTask       = _advertisementServices.Query();
            var ad             = await roleModuleTask;
            var list           = await listTask;


            // 测试service层返回异常
            _advertisementServices.ReturnExp();

            Love love = null;

            love.SayLoveU();

            return(data);
        }
Beispiel #5
0
        public async Task <MessageModel <ResponseEnum> > Get()
        {
            var data = new MessageModel <ResponseEnum>();

            /*
             *  测试 sql 查询
             */
            var queryBySql = await _blogArticleServices.QuerySql("SELECT bsubmitter,btitle,bcontent,bCreateTime FROM BlogArticle WHERE bID>5");

            /*
             *  测试按照指定列查询
             */
            var queryByColums = await _blogArticleServices
                                .Query <BlogViewModels>(it => new BlogViewModels()
            {
                btitle = it.btitle
            });

            /*
             *  测试 sql 更新
             *
             * 【SQL参数】:@bID:5
             *  @bsubmitter:laozhang619
             *  @IsDeleted:False
             * 【SQL语句】:UPDATE `BlogArticle`  SET
             *  `bsubmitter`=@bsubmitter,`IsDeleted`=@IsDeleted  WHERE `bID`=@bID
             */
            var updateSql = await _blogArticleServices.Update(new { bsubmitter = $"laozhang{DateTime.Now.Millisecond}", IsDeleted = false, bID = 5 });


            // 测试模拟异常,全局异常过滤器拦截
            var i = 0;
            var d = 3 / i;


            // 测试 AOP 缓存
            var blogArticles = await _blogArticleServices.GetBlogs();


            // 测试多表联查
            var roleModulePermissions = await _roleModulePermissionServices.QueryMuchTable();


            // 测试多个异步执行时间
            var roleModuleTask = _roleModulePermissionServices.Query();
            var listTask       = _advertisementServices.Query();
            var ad             = await roleModuleTask;
            var list           = await listTask;


            // 测试service层返回异常
            _advertisementServices.ReturnExp();

            return(data);
        }
        public BaseResponse GetNavigationBar(int uid)
        {
            if (uid > 0)
            {
                var roleId = _userRoleServices.Get(d => d.IsDeleted == false && d.UserId == uid)?.RoleId;
                if (roleId > 0)
                {
                    var pids = _roleModulePermissionServices.Query(d => d.IsDeleted == false && d.RoleId == roleId).Select(d => d.PermissionId).Distinct();
                    if (pids.Any())
                    {
                        var rolePermissionMoudles = _permissionServices.Query(d => pids.Contains(d.Id) && d.IsButton == false).OrderBy(c => c.OrderSort);
                        var permissionTrees       = (from child in rolePermissionMoudles
                                                     where child.IsDeleted == false
                                                     orderby child.Id
                                                     select new NavigationBar
                        {
                            id = child.Id,
                            name = child.Name,
                            pid = (int)child.Pid,
                            order = child.OrderSort,
                            path = child.Code,
                            iconCls = child.Icon,
                            key = child.Key,
                            component = child.Component,
                            isbutton = child.IsButton,
                            meta = new NavigationBarMeta
                            {
                                requireAuth = true,
                                title = child.Name,
                                icon = child.Icon
                            }
                        }).ToList();
                        NavigationBar rootRoot = new NavigationBar()
                        {
                            id        = 0,
                            pid       = 0,
                            order     = 0,
                            name      = "根节点",
                            path      = "",
                            iconCls   = "",
                            component = "BasicLayout",
                            key       = "",
                            meta      = new NavigationBarMeta(),
                        };
                        permissionTrees = permissionTrees.OrderBy(d => d.order).ToList();

                        RecursionHelper.LoopNaviBarAppendChildren(permissionTrees, rootRoot);
                        List <NavigationBar> list = new List <NavigationBar>();
                        list.Add(rootRoot);
                        return(new SuccessResponse(list));
                    }
                }
            }
            return(new SuccessResponse());
        }
Beispiel #7
0
        public async Task <MessageModel <ResponseEnum> > Get()
        {
            var data = new MessageModel <ResponseEnum>();

            await _redisBasketRepository.ListLeftPushAsync(RedisMqKey.Loging, "xxxxxxxxxxxxxxxxxxx");

            /*
             *  测试 sql 查询
             */
            var queryBySql = await _blogArticleServices.QuerySql("SELECT bsubmitter,btitle,bcontent,bCreateTime FROM BlogArticle WHERE bID>5");


            /*
             *  测试 sql 更新
             *
             * 【SQL参数】:@bID:5
             *  @bsubmitter:laozhang619
             *  @IsDeleted:False
             * 【SQL语句】:UPDATE `BlogArticle`  SET
             *  `bsubmitter`=@bsubmitter,`IsDeleted`=@IsDeleted  WHERE `bID`=@bID
             */
            var updateSql = await _blogArticleServices.Update(new { bsubmitter = $"laozhang{DateTime.Now.Millisecond}", IsDeleted = false, bID = 5 });


            // 测试模拟异常,全局异常过滤器拦截
            var i = 0;
            var d = 3 / i;


            // 测试 AOP 缓存
            var blogArticles = await _blogArticleServices.GetBlogs();


            // 测试多表联查
            var roleModulePermissions = await _roleModulePermissionServices.QueryMuchTable();


            // 测试多个异步执行时间
            var roleModuleTask = _roleModulePermissionServices.Query();
            var listTask       = _advertisementServices.Query();
            var ad             = await roleModuleTask;
            var list           = await listTask;


            // 测试service层返回异常
            _advertisementServices.ReturnExp();

            Love love = null;

            love.SayLoveU();

            return(data);
        }
        public async Task<ApiResponseModel<NavigationBarDto>> GetNavigationBar(int uid)
        {
            var token = _httpContext.HttpContext.Request.Headers["Authorization"].ObjToString().Replace("Bearer ", "");
            var id = JwtHelper.SerializeJwt(token)?.Uid;
            if (id != uid)
            {
                return ApiResponse.Error<NavigationBarDto>("参数和token不一样");
            }
            var roleIds = (await _userRoleServices.Query(m => m.IsDeleted == false && m.UserId == id)).Select(m => m.RoleId).Distinct().ToList();
            if (!roleIds.Any())
            {
                return ApiResponse.Error<NavigationBarDto>("用户未分配角色");
            }
            var permissionIds = (await _roleModulePermissionServices.Query(d => d.IsDeleted == false && roleIds.Contains(d.RoleId))).Select(m => m.PermissionId).Distinct().ToList();
            var permissionList = (await _permissionServices.Query(m => permissionIds.Contains(m.Id) && m.IsDeleted == false)).OrderBy(c => c.OrderSort).ToList();
            var permissionTree = permissionList.Select(child => new NavigationBarDto
            {

                id = child.Id,
                name = child.Name,
                pid = child.Pid,
                order = child.OrderSort,
                path = child.Code,
                iconCls = child.Icon,
                Func = child.Func,
                IsHide = child.IsHide.ObjToBool(),
                IsButton = child.IsButton.ObjToBool(),
                meta = new NavigationBarMetaDto
                {
                    requireAuth = true,
                    title = child.Name,
                    NoTabPage = child.IsHide.ObjToBool()
                }
            }).ToList();
            NavigationBarDto rootRoot = new NavigationBarDto
            {
                id = 0,
                pid = 0,
                order = 0,
                name = "根节点",
                path = "",
                iconCls = "",
                meta = new NavigationBarMetaDto(),

            };
            LoopNaviBarAppendChildren(permissionTree, rootRoot);
            return ApiResponse.Success(rootRoot);
        }
Beispiel #9
0
        public async Task <MessageModel <string> > SaveData2TsvAsync()
        {
            var data = new MessageModel <string>()
            {
                success = true, msg = ""
            };

            if (_env.IsDevelopment())
            {
                JsonSerializerSettings microsoftDateFormatSettings = new JsonSerializerSettings
                {
                    DateFormatHandling = DateFormatHandling.MicrosoftDateFormat
                };

                // 取出数据,序列化,自己可以处理判空
                var rolesJson = JsonConvert.SerializeObject(await _roleServices.Query(d => d.IsDeleted == false), microsoftDateFormatSettings);
                FileHelper.WriteFile(Path.Combine(_env.WebRootPath, "BlogCore.Data.json", "Role_New.tsv"), rolesJson, Encoding.UTF8);


                var permissionsJson = JsonConvert.SerializeObject(await _permissionServices.Query(d => d.IsDeleted == false), microsoftDateFormatSettings);
                FileHelper.WriteFile(Path.Combine(_env.WebRootPath, "BlogCore.Data.json", "Permission_New.tsv"), permissionsJson, Encoding.UTF8);


                var modulesJson = JsonConvert.SerializeObject(await _moduleServices.Query(d => d.IsDeleted == false), microsoftDateFormatSettings);
                FileHelper.WriteFile(Path.Combine(_env.WebRootPath, "BlogCore.Data.json", "Modules_New.tsv"), modulesJson, Encoding.UTF8);


                var rmpsJson = JsonConvert.SerializeObject(await _roleModulePermissionServices.Query(d => d.IsDeleted == false), microsoftDateFormatSettings);
                FileHelper.WriteFile(Path.Combine(_env.WebRootPath, "BlogCore.Data.json", "RoleModulePermission_New.tsv"), rmpsJson, Encoding.UTF8);



                data.success = true;
                data.msg     = "生成成功!";
            }
            else
            {
                data.success = false;
                data.msg     = "当前不处于开发模式,代码生成不可用!";
            }

            return(data);
        }
Beispiel #10
0
        public async Task <MessageModel <ResponseEnum> > Get()
        {
            var data = new MessageModel <ResponseEnum>();

            var roleModuleTask = _roleModulePermissionServices.Query();
            var listTask       = _advertisementServices.Query();

            var ad   = await roleModuleTask;
            var list = await listTask;


            _advertisementServices.ReturnExp();

            Love love = null;

            love.SayLoveU();

            return(data);
        }