Ejemplo n.º 1
0
        public async Task <MessageModel <string> > Post([FromBody] Role role)
        {
            role.CreateId = _user.ID;
            role.CreateBy = _user.Name;
            var id = (await _roleServices.Add(role));

            return(id > 0 ? Success(id.ObjToString(), "添加成功") : Failed("添加失败"));
        }
Ejemplo n.º 2
0
        public async Task <MessageModel <string> > Post([FromBody] Role role)
        {
            var data = new MessageModel <string>();

            var id = (await _roleServices.Add(role));

            data.success = id > 0;
            if (data.success)
            {
                data.response = id.ObjToString();
                data.msg      = "添加成功";
            }

            return(data);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> AddRole(AddRoleViewModel vm)
        {
            var role = (await _roleServices.Query(p => p.Name == vm.Name)).SingleOrDefault();

            if (role != null)
            {
                throw new UserOperationException("该角色已存在");
            }
            role            = _mapper.Map <SysRole>(vm);
            role.CreateTime = DateTime.Now;
            role.Enabled    = true;
            var result = _roleServices.Add(role);

            if (result <= 0)
            {
                throw new UserOperationException("添加失败");
            }
            return(Ok(new JsonResponse(true)));
        }
        public async Task <BaseResponse <string> > Post(Role role)
        {
            var data = new BaseResponse <string>();

            //role.CreateId = _user.ID;
            //role.CreateBy = _user.Name;
            //role.CreateBy = "yyj";
            //role.DataFlag = 1;
            //role.Name = "admin";
            //role.Description = "admin的权限";
            //role.CreateId = 0;
            //role.CreateTime = DateTime.Now;
            role.UpdateName = role.CreatedName;
            role.UpdateId   = role.CreatedId;
            var id = await _roleServices.Add(role);

            if (id > 0)
            {
                data.Msg = "添加成功";
            }
            return(data);
        }
Ejemplo n.º 5
0
        public async Task <MessageModel <string> > DataMigrateFromOld2New()
        {
            var data = new MessageModel <string>()
            {
                success = true, msg = ""
            };

            if (_env.IsDevelopment())
            {
                try
                {
                    // 获取权限集合数据
                    var rmps = await _roleModulePermissionServices.GetRMPMaps();

                    // 当然,你可以做个where查询
                    //rmps = rmps.Where(d => d.ModuleId > 88).ToList();

                    // 开启事务,保证数据一致性
                    _unitOfWork.BeginTran();

                    var rid   = 0;
                    var pid   = 0;
                    var mid   = 0;
                    var rpmid = 0;

                    // 注意信息的完整性,不要重复添加,确保主库没有要添加的数据
                    foreach (var item in rmps)
                    {
                        // 角色信息,防止重复添加,做了判断
                        if (item.Role != null)
                        {
                            var isExit = (await _roleServices.Query(d => d.Name == item.Role.Name && d.IsDeleted == false)).FirstOrDefault();
                            if (isExit == null)
                            {
                                rid = await _roleServices.Add(item.Role);

                                Console.WriteLine($"Role Added:{item.Role.Name}");
                            }
                            else
                            {
                                rid = isExit.Id;
                            }
                        }

                        // 菜单
                        if (item.Permission != null)
                        {
                            pid = await _permissionServices.Add(item.Permission);

                            Console.WriteLine($"Permission Added:{item.Permission.Name}");
                        }

                        // 接口
                        if (item.Module != null)
                        {
                            mid = await _moduleServices.Add(item.Module);

                            Console.WriteLine($"Module Added:{item.Module.LinkUrl}");
                        }

                        // 关系
                        if (rid > 0 && pid > 0 && mid > 0)
                        {
                            rpmid = await _roleModulePermissionServices.Add(new RoleModulePermission()
                            {
                                IsDeleted    = false,
                                CreateTime   = DateTime.Now,
                                ModifyTime   = DateTime.Now,
                                ModuleId     = mid,
                                PermissionId = pid,
                                RoleId       = rid,
                            });

                            Console.WriteLine($"RMP Added:{rpmid}");
                        }
                    }


                    _unitOfWork.CommitTran();

                    data.success = true;
                    data.msg     = "导入成功!";
                }
                catch (Exception)
                {
                    _unitOfWork.RollbackTran();
                }
            }
            else
            {
                data.success = false;
                data.msg     = "当前不处于开发模式,代码生成不可用!";
            }

            return(data);
        }
Ejemplo n.º 6
0
        public int RoleAdd(JurisdictionInfo jurisdictionInfo)
        {
            var roleAdd = _roleServices.Add(jurisdictionInfo);

            return(roleAdd);
        }
Ejemplo n.º 7
0
        public async Task <MessageModel <string> > DataMigrateFromOld2New()
        {
            var data = new MessageModel <string>()
            {
                success = true, msg = ""
            };
            var filterPermissionId = 122;

            if (_env.IsDevelopment())
            {
                try
                {
                    var apiList = await _moduleServices.Query(d => d.IsDeleted == false);

                    var permissionsAllList = await _permissionServices.Query(d => d.IsDeleted == false);

                    var permissions = permissionsAllList.Where(d => d.Pid == 0).ToList();
                    var rmps        = await _roleModulePermissionServices.GetRMPMaps();

                    List <PM> pms = new();

                    // 当然,你可以做个where查询
                    rmps = rmps.Where(d => d.PermissionId >= filterPermissionId).ToList();

                    InitPermissionTree(permissions, permissionsAllList, apiList);

                    var        actionPermissionIds = permissionsAllList.Where(d => d.Id >= filterPermissionId).Select(d => d.Id).ToList();
                    List <int> filterPermissionIds = new();
                    FilterPermissionTree(permissionsAllList, actionPermissionIds, filterPermissionIds);
                    permissions = permissions.Where(d => filterPermissionIds.Contains(d.Id)).ToList();

                    // 开启事务,保证数据一致性
                    _unitOfWork.BeginTran();

                    // 注意信息的完整性,不要重复添加,确保主库没有要添加的数据

                    // 1、保持菜单和接口
                    await SavePermissionTreeAsync(permissions, pms);

                    var rid   = 0;
                    var pid   = 0;
                    var mid   = 0;
                    var rpmid = 0;

                    // 2、保存关系表
                    foreach (var item in rmps)
                    {
                        // 角色信息,防止重复添加,做了判断
                        if (item.Role != null)
                        {
                            var isExit = (await _roleServices.Query(d => d.Name == item.Role.Name && d.IsDeleted == false)).FirstOrDefault();
                            if (isExit == null)
                            {
                                rid = await _roleServices.Add(item.Role);

                                Console.WriteLine($"Role Added:{item.Role.Name}");
                            }
                            else
                            {
                                rid = isExit.Id;
                            }
                        }

                        pid = (pms.FirstOrDefault(d => d.PidOld == item.PermissionId)?.PidNew).ObjToInt();
                        mid = (pms.FirstOrDefault(d => d.MidOld == item.ModuleId)?.MidNew).ObjToInt();
                        // 关系
                        if (rid > 0 && pid > 0)
                        {
                            rpmid = await _roleModulePermissionServices.Add(new RoleModulePermission()
                            {
                                IsDeleted    = false,
                                CreateTime   = DateTime.Now,
                                ModifyTime   = DateTime.Now,
                                ModuleId     = mid,
                                PermissionId = pid,
                                RoleId       = rid,
                            });

                            Console.WriteLine($"RMP Added:{rpmid}");
                        }
                    }


                    _unitOfWork.CommitTran();

                    data.success = true;
                    data.msg     = "导入成功!";
                }
                catch (Exception)
                {
                    _unitOfWork.RollbackTran();
                }
            }
            else
            {
                data.success = false;
                data.msg     = "当前不处于开发模式,代码生成不可用!";
            }

            return(data);
        }