コード例 #1
0
ファイル: SysApiService.cs プロジェクト: jinjupeng/MPShop
        public MsgModel DeleteApi(sys_api sys_Api)
        {
            // 查找被删除节点的子节点
            List <sys_api> myChild = _baseService.GetModels(s => s.api_pids.Contains("[" + sys_Api.id + "]")).ToList();

            if (myChild.Count > 0)
            {
                // "不能删除含有下级API接口的节点"
            }
            //查找被删除节点的父节点
            List <sys_api> myFatherChild = _baseService.GetModels(s => s.api_pids.Contains("[" + sys_Api.api_pid + "]")).ToList();

            //我的父节点只有我这一个子节点,而我还要被删除,更新父节点为叶子节点。
            if (myFatherChild.Count == 1)
            {
                sys_api parent = new sys_api
                {
                    id      = sys_Api.api_pid,
                    is_leaf = true // //更新父节点为叶子节点。
                };
                _baseService.Update(parent);
            }
            // 删除节点
            _baseService.Remove(sys_Api);
            return(MsgModel.Success("删除接口配置成功!"));
        }
コード例 #2
0
 public MsgModel SaveCheckedKeys(int roleId, List <int> checkedIds)
 {
     // 保存之前先删除
     _baseSysRoleMenuService.DeleteRange(_baseSysRoleMenuService.GetModels(a => a.role_id == roleId).ToList());
     _mySystemService.InsertRoleMenuIds(roleId, checkedIds);
     return(MsgModel.Success("保存菜单权限成功!"));
 }
コード例 #3
0
        public async Task <IActionResult> Upload([FromForm] IFormCollection form)
        {
            var formFile    = form.Files.FirstOrDefault();
            var uploadModel = new FileUploadModel
            {
                Request  = Request,
                FormFile = formFile,
                RootPath = _filePathConfig.UploadPath,
                Module   = "Admin",
                Group    = Path.Combine("OSS", "Open"),
                SubPath  = Path.Combine("code", "file")
            };

            var fileUploadResult = await _fileUploadService.UploadAsync(uploadModel);

            var fileInfo = new FileInfo(formFile.FileName)
            {
                SaveName = formFile.FileName,
                Path     = "resource/"
            };

            var fileInfoResult = fileUploadResult.data as FileInfo;
            var fileObj        = new FileObject
            {
                PhysicalPath = Path.Combine(_filePathConfig.UploadPath, fileInfoResult.FullPath),
                AccessMode   = FileAccessMode.Private,
                Group        = Path.Combine("OSS", "Open"),
                ModuleCode   = "Admin",
                FileInfo     = fileInfo
            };
            var fileStorageResult = _fileStorageService.Upload(fileObj);

            return(Ok(await Task.FromResult(MsgModel.Success(fileStorageResult))));
        }
コード例 #4
0
        public MsgModel DeleteMenu(sys_menu sys_menu)
        {
            //查找被删除节点的子节点
            List <sys_menu> myChilds = _baseSysMenuService.GetModels(a => a.menu_pids.Contains("[" + sys_menu.id + "]")).ToList();

            if (myChilds.Count > 0)
            {
                // "不能删除含有下级菜单的菜单"
                return(MsgModel.Fail("不能删除含有下级菜单的菜单"));
            }
            //查找被删除节点的父节点
            List <sys_menu> myFatherChilds = _baseSysMenuService.GetModels(a => a.menu_pids.Contains("[" + sys_menu.menu_pid + "]")).ToList();

            //我的父节点只有我这一个子节点,而我还要被删除,更新父节点为叶子节点。
            if (myFatherChilds.Count == 1)
            {
                sys_menu parent = _baseSysMenuService.GetModels(a => a.id == sys_menu.menu_pid).SingleOrDefault();
                parent.id      = sys_menu.menu_pid;
                parent.is_leaf = true;//更新父节点为叶子节点。
                _baseSysMenuService.Update(parent);
            }
            // 删除节点
            _baseSysMenuService.Remove(sys_menu);
            return(MsgModel.Success("删除菜单项成功!"));
        }
コード例 #5
0
ファイル: JwtAuthService.cs プロジェクト: jinjupeng/MPShop
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public MsgModel Login(string username, string password)
        {
            if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
            {
                return(MsgModel.Fail("用户名或密码为空!"));
            }
            // 加密登陆密码
            string encodePassword = PasswordEncoder.Encode(password);

            sys_user sys_user = _baseService.GetModels(a => a.username == username && a.password == encodePassword).SingleOrDefault();

            if (sys_user == null)
            {
                return(MsgModel.Fail("用户名或密码不正确!"));
            }
            else if (sys_user.enabled == false)
            {
                return(MsgModel.Fail("账户已被禁用!"));
            }

            // 将一些个人数据写入token中
            var dict = new Dictionary <string, object>
            {
                { ClaimAttributes.UserId, sys_user.id },
                { ClaimAttributes.UserName, username }
            };

            var data = JwtHelper.IssueJwt(dict);

            return(MsgModel.Success((object)data));
        }
コード例 #6
0
        public MsgModel GetSysConfigList()
        {
            List <sys_config> list = _baseSysConfigService.GetModels(null).ToList();
            var data = list.BuildAdapter().AdaptToType <List <SysConfig> >();

            return(MsgModel.Success(data, "查询成功!"));
        }
コード例 #7
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public MsgModel Login(string username, string password)
        {
            if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
            {
                return(MsgModel.Fail("用户名或密码为空!"));
            }
            // 加密登陆密码
            string encodePassword = PasswordEncoder.Encode(password);

            sys_user sys_user = _baseService.GetModels(a => a.username == username && a.password == encodePassword).SingleOrDefault();

            if (sys_user == null)
            {
                return(MsgModel.Fail("用户名或密码不正确!"));
            }
            else if (sys_user.enabled == false)
            {
                return(MsgModel.Fail("账户已被禁用!"));
            }

            // 将一些个人数据写入token中
            var customClaims = new List <Claim>
            {
                new Claim(ClaimAttributes.UserId, Convert.ToString(sys_user.id)),
                new Claim(ClaimAttributes.UserName, username)
            };

            var data = _jwtHelper.IssueJwt(customClaims);

            return(MsgModel.Success((object)data));
        }
コード例 #8
0
        /// <summary>
        /// 新增数据字典项
        /// </summary>
        /// <param name="sys_Dict"></param>
        public MsgModel Add(sys_dict sys_Dict)
        {
            sys_Dict.id = new Snowflake().GetId();
            var result = _baseSysDictService.AddRange(sys_Dict);

            return(result ? MsgModel.Success("新增数据字典项成功!") : MsgModel.Fail("新增数据字典项失败!"));
        }
コード例 #9
0
        /// <summary>
        /// 查询所有
        /// </summary>
        /// <returns></returns>
        public MsgModel All()
        {
            List <sys_dict> list = _baseSysDictService.GetModels(null).ToList();
            var             data = list.BuildAdapter().AdaptToType <List <SysDict> >();

            return(MsgModel.Success(data, "查询成功!"));
        }
コード例 #10
0
        public MsgModel AddConfig(sys_config sys_Config)
        {
            sys_Config.id = new Snowflake().GetId();
            var result = _baseSysConfigService.AddRange(sys_Config);

            return(result ? MsgModel.Success("新增配置成功!") : MsgModel.Fail("新增配置失败!"));
        }
コード例 #11
0
        public MsgModel DeleteOrg(sys_org sys_org)
        {
            List <sys_org> myChilds = _baseSysOrgService.GetModels(a => a.org_pids.Contains("[" + sys_org.org_pid + "]")).ToList();

            if (myChilds.Count > 0)
            {
                // "不能删除有下级组织的组织机构"
                throw new CustomException((int)HttpStatusCode.Status500InternalServerError, "不能删除有下级组织的组织机构");
            }
            List <sys_org> myFatherChilds = _baseSysOrgService.GetModels(a => a.org_pids.Contains("[" + "]")).ToList();

            //我的父节点只有我这一个子节点,而我还要被删除,更新父节点为叶子节点。
            if (myFatherChilds.Count == 1)
            {
                sys_org parent = new sys_org
                {
                    id      = sys_org.org_pid,
                    is_leaf = true// 更新父节点为叶子节点。
                };
                _baseSysOrgService.Update(parent);
            }
            // 删除节点
            _baseSysOrgService.Remove(sys_org);
            return(MsgModel.Success("删除组织机构成功!"));
        }
コード例 #12
0
 /// <summary>
 /// 用户管理:删除
 /// </summary>
 /// <param name="userId"></param>
 public MsgModel DeleteUser(long userId)
 {
     if (!_baseSysUserService.DeleteRange(_baseSysUserService.GetModels(a => a.id == userId)))
     {
         return(MsgModel.Fail(StatusCodes.Status500InternalServerError, "删除用户失败!"));
     }
     return(MsgModel.Success("删除用户成功!"));
 }
コード例 #13
0
 public MsgModel DeleteRole(int id)
 {
     if (!_baseSysRoleService.DeleteRange(_baseSysRoleService.GetModels(a => a.id == id)))
     {
         return(MsgModel.Fail("删除角色失败!"));
     }
     return(MsgModel.Success("删除角色成功!"));
 }
コード例 #14
0
 /// <summary>
 /// 用户管理:修改
 /// </summary>
 /// <param name="sys_user"></param>
 public MsgModel UpdateUser(sys_user sys_user)
 {
     if (!_baseSysUserService.UpdateRange(sys_user))
     {
         return(MsgModel.Fail(StatusCodes.Status500InternalServerError, "更新用户失败!"));
     }
     return(MsgModel.Success("更新用户成功"));
 }
コード例 #15
0
 public MsgModel UpdateRole(sys_role sys_role)
 {
     if (!_baseSysRoleService.Update(sys_role))
     {
         return(MsgModel.Fail("角色更新失败!"));
     }
     return(MsgModel.Success("角色更新成功!"));
 }
コード例 #16
0
        /// <summary>
        /// 用户管理:更新用户的激活状态
        /// </summary>
        /// <param name="id"></param>
        /// <param name="enabled"></param>
        public MsgModel UpdateEnabled(long id, bool enabled)
        {
            sys_user sys_user = _baseSysUserService.GetModels(a => a.id == id).SingleOrDefault();

            sys_user.enabled = enabled;
            bool result = _baseSysUserService.UpdateRange(sys_user);

            return(result ? MsgModel.Success("用户状态更新成功!") : MsgModel.Fail("用户状态更新失败!"));
        }
コード例 #17
0
        /// <summary>
        /// 组织管理:更新组织的禁用状态
        /// </summary>
        /// <param name="id"></param>
        /// <param name="status"></param>
        public MsgModel UpdateStatus(int id, bool status)
        {
            sys_org sys_org = _baseSysOrgService.GetModels(a => a.id == id).SingleOrDefault();

            sys_org.status = status;
            bool result = _baseSysOrgService.Update(sys_org);

            return(result ? MsgModel.Success("更新组织机构状态成功!") : MsgModel.Fail("更新组织机构状态失败!"));
        }
コード例 #18
0
        public IDataShell <MsgModel> Get(string contid)
        {
            var res = new MsgModel()
            {
                MsgId = "1", MsgText = "msg text", MsgTime = DateTime.Now, IsRead = false
            };

            return(res.Success());
        }
コード例 #19
0
        public MsgModel UpdateOrg(sys_org sys_org)
        {
            if (!_baseSysOrgService.Update(sys_org))
            {
                return(MsgModel.Fail("更新组织机构失败!"));
            }

            return(MsgModel.Success("更新组织机构成功!"));
        }
コード例 #20
0
ファイル: SysApiService.cs プロジェクト: jinjupeng/MPShop
        /// <summary>
        /// 接口管理:更新接口的禁用状态
        /// </summary>
        /// <param name="id"></param>
        /// <param name="status"></param>
        public MsgModel UpdateStatus(int id, bool status)
        {
            sys_api sys_Api = _baseService.GetModels(a => a.id == id).SingleOrDefault();

            sys_Api.status = status;
            bool result = _baseService.Update(sys_Api);

            return(MsgModel.Success(result ? "接口禁用状态更新成功!" : "接口禁用状态更新失败!"));
        }
コード例 #21
0
        /// <summary>
        /// 判断当前登录的用户密码是否是默认密码,如果是,会让他去修改
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public MsgModel IsDefault(string userName)
        {
            sys_user sys_user = _baseSysUserService.GetModels(a => a.username == userName).SingleOrDefault();
            //判断数据库密码是否是默认密码
            var result = PasswordEncoder.IsMatch(sys_user.password, _sysConfigService.GetConfigItem("user.init.password"));

            //判断数据库密码是否是默认密码
            return(MsgModel.Success(result, "获取成功!"));
        }
コード例 #22
0
ファイル: SysApiService.cs プロジェクト: jinjupeng/MPShop
        public MsgModel SaveCheckedKeys(int roleId, List <int> checkedIds)
        {
            // 保存之前先删除
            var sysRoleApiList = _baseSysRoleApiService.GetModels(a => a.role_id == roleId);

            _baseSysRoleApiService.DeleteRange(sysRoleApiList);
            _mySystemService.InsertRoleApiIds(roleId, checkedIds);
            return(MsgModel.Success("保存接口权限成功!"));
        }
コード例 #23
0
        /// <summary>
        /// 角色管理:更新角色的禁用状态
        /// </summary>
        /// <param name="id"></param>
        /// <param name="status"></param>
        public MsgModel UpdateStatus(int id, bool status)
        {
            sys_role sys_role = _baseSysRoleService.GetModels(a => a.id == id).SingleOrDefault();

            sys_role.status = status;
            bool result = _baseSysRoleService.Update(sys_role);

            return(result ? MsgModel.Success("角色禁用状态更新成功!") : MsgModel.Fail("角色禁用状态更新失败!"));
        }
コード例 #24
0
        /// <summary>
        /// 菜单管理:更新菜单的禁用状态
        /// </summary>
        /// <param name="id"></param>
        /// <param name="status"></param>
        public MsgModel UpdateStatus(int id, bool status)
        {
            sys_menu sys_menu = _baseSysMenuService.GetModels(a => a.id == id).SingleOrDefault();

            sys_menu.id     = id;
            sys_menu.status = status;
            var result = _baseSysMenuService.Update(sys_menu);

            return(result ? MsgModel.Success("菜单禁用状态更新成功!") : MsgModel.Fail("菜单禁用状态更新失败!"));
        }
コード例 #25
0
        /// <summary>
        /// 根据登录用户名查询用户信息
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public MsgModel GetUserByUserName(string userName)
        {
            sys_user sysUser = _baseSysUserService.GetModels(a => a.username == userName).SingleOrDefault();

            if (sysUser != null)
            {
                sysUser.password = "";
            }

            return(MsgModel.Success(sysUser));
        }
コード例 #26
0
        /// <summary>
        /// 获取角色记录及某用户勾选角色记录
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public MsgModel GetRolesAndChecked(int userId)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>
            {
                // 所有角色记录
                { "roleDatas", _baseSysRoleService.GetModels(a => a.status == false).ToList().BuildAdapter().AdaptToType <List <SysRole> >() },
                //某用户具有的角色id列表
                { "checkedRoleIds", _mySystemService.GetCheckedRoleIds(userId) }
            };

            return(MsgModel.Success(dict, "查询成功!"));
        }
コード例 #27
0
        public MsgModel QueryConfigs(string configLik)
        {
            Expression <Func <sys_config, bool> > express = null;

            if (!string.IsNullOrEmpty(configLik))
            {
                express = a => a.param_name.Contains(configLik) || a.param_key.Contains(configLik);
            }
            List <sys_config> list = _baseSysConfigService.GetModels(express).ToList();
            var data = list.BuildAdapter().AdaptToType <List <SysConfig> >();

            return(MsgModel.Success(data, "查询成功!"));
        }
コード例 #28
0
        /// <summary>
        /// 根据参数查询角色记录
        /// </summary>
        /// <param name="roleLik">角色编码 或角色描述 或角色名称模糊查询</param>
        /// <returns>角色记录列表</returns>
        public MsgModel QueryRoles(string roleLik)
        {
            Expression <Func <sys_role, bool> > express = null;

            if (!string.IsNullOrWhiteSpace(roleLik))
            {
                express = a => a.role_code.Contains(roleLik) || a.role_desc.Contains(roleLik) || a.role_name.Contains(roleLik);
            }
            var sysRoleList = _baseSysRoleService.GetModels(express).ToList();
            var data        = sysRoleList.BuildAdapter().AdaptToType <List <SysRole> >();

            return(MsgModel.Success(data, "查询成功!"));
        }
コード例 #29
0
 public MsgModel AddRole(sys_role sys_role)
 {
     sys_role.status = false;// 是否禁用:false
     if (_baseSysRoleService.GetModels(a => a.role_code == sys_role.role_code).Any())
     {
         return(MsgModel.Fail(StatusCodes.Status500InternalServerError, "角色编码已存在,不能重复!"));
     }
     if (!_baseSysRoleService.Insert(sys_role))
     {
         return(MsgModel.Fail("新增角色失败!"));
     }
     return(MsgModel.Success("新增角色成功!"));
 }
コード例 #30
0
        public MsgModel AddOrg(sys_org sys_org)
        {
            SetOrgIdsAndLevel(sys_org);
            sys_org.is_leaf = true;//新增的组织节点都是子节点,没有下级
            sys_org parent = _baseSysOrgService.GetModels(a => a.id == sys_org.org_pid).SingleOrDefault();

            parent.id      = sys_org.org_pid;
            parent.is_leaf = false; //更新父节点为非子节点。
            _baseSysOrgService.Update(parent);

            sys_org.status = false;//设置是否禁用,新增节点默认可用
            _baseSysOrgService.Add(sys_org);
            return(MsgModel.Success("新增组织机构成功!"));
        }