/// <summary>
        /// 添加或修改用户组
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="GroupName">新名字</param>
        /// <param name="ParentId">父级组</param>
        /// <param name="appid">appid</param>
        /// <returns></returns>
        public ActionResult Save(int Id = 0, string GroupName = "", int?ParentId = null, string appid = "")
        {
            ParentId = ParentId == 0 ? null : ParentId;
            UserGroup group = UserGroupBll.GetById(Id);

            if (group != null)
            {
                //修改
                if (UserGroupBll.Any(a => a.GroupName.Equals(GroupName) && !a.GroupName.Equals(group.GroupName)))
                {
                    return(ResultData(null, false, $"{GroupName} 用户组已经存在!"));
                }
                group.GroupName = GroupName;
                group.ParentId  = ParentId;
                bool b = UserGroupBll.UpdateEntitySaved(@group);
                return(ResultData(null, b, b ? "修改成功" : "修改失败!"));
            }
            //添加
            if (UserGroupBll.Any(a => a.GroupName.Equals(GroupName)))
            {
                return(ResultData(null, false, $"{GroupName} 用户组已经存在!"));
            }
            group = new UserGroup {
                GroupName = GroupName, ParentId = ParentId
            };
            if (!string.IsNullOrEmpty(appid) && ClientAppBll.Any(a => a.AppId.Equals(appid)))
            {
                var app = ClientAppBll.GetFirstEntity(a => a.AppId.Equals(appid));
                app.UserGroup.Add(group);
                bool b = ClientAppBll.UpdateEntitySaved(app);
                return(ResultData(null, b, b ? "用户组添加成功!" : "用户组添加失败!"));
            }
            group = UserGroupBll.AddEntitySaved(group);
            return(@group != null?ResultData(@group, true, "用户组添加成功!") : ResultData(null, false, "用户组添加失败!"));
        }
        /// <summary>
        /// 添加或修改菜单
        /// </summary>
        /// <param name="model"></param>
        /// <param name="appid"></param>
        /// <returns></returns>
        public ActionResult Save(MenuInputDto model, string appid)
        {
            model.ParentId = model.ParentId == 0 ? null : model.ParentId;
            if (string.IsNullOrEmpty(model.IconUrl) || !model.IconUrl.Contains("/"))
            {
                model.IconUrl = null;
            }

            Menu m = MenuBll.GetById(model.Id);

            if (m == null)
            {
                if (!string.IsNullOrEmpty(appid) && ClientAppBll.Any(a => a.AppId.Equals(appid)))
                {
                    ClientApp app = ClientAppBll.GetFirstEntity(a => a.AppId.Equals(appid));
                    app.Menus.Add(model.Mapper <Menu>());
                    bool saved = ClientAppBll.UpdateEntitySaved(app);
                    return(ResultData(null, saved, saved ? "添加成功" : "添加失败"));
                }

                var menu = MenuBll.AddEntitySaved(model.Mapper <Menu>());
                return(menu != null?ResultData(menu, true, "添加成功") : ResultData(null, false, "添加失败"));
            }

            Mapper.Map(model, m);
            bool b = MenuBll.UpdateEntitySaved(m);

            return(ResultData(null, b, b ? "修改成功" : "修改失败"));
        }
Esempio n. 3
0
        /// <summary>
        /// 从应用移除权限
        /// </summary>
        /// <param name="id"></param>
        /// <param name="pids"></param>
        /// <returns></returns>
        public ActionResult RemovePermissions(int id, string pids)
        {
            string[]  ids = pids.Split(',');
            ClientApp app = ClientAppBll.GetById(id);

            if (app is null)
            {
                return(ResultData(null, false, "未找到应用!"));
            }

            List <Permission> permissions = PermissionBll.LoadEntities(u => ids.Contains(u.Id.ToString())).ToList();

            permissions.ForEach(u => { app.Permissions.Remove(u); });
            bool b = ClientAppBll.UpdateEntitySaved(app);

            return(ResultData(null, b, b ? "移除权限成功!" : "移除权限失败!"));
        }
Esempio n. 4
0
        /// <summary>
        /// 从应用移除角色
        /// </summary>
        /// <param name="id"></param>
        /// <param name="rids"></param>
        /// <returns></returns>
        public ActionResult RemoveRoles(int id, string rids)
        {
            string[]  ids = rids.Split(',');
            ClientApp app = ClientAppBll.GetById(id);

            if (app is null)
            {
                return(ResultData(null, false, "未找到应用!"));
            }

            List <Role> roles = RoleBll.LoadEntities(u => ids.Contains(u.Id.ToString())).ToList();

            roles.ForEach(u => { app.Roles.Remove(u); });
            bool b = ClientAppBll.UpdateEntitySaved(app);

            return(ResultData(null, b, b ? "移除角色成功!" : "移除角色失败!"));
        }
Esempio n. 5
0
        /// <summary>
        /// 从应用移除用户组
        /// </summary>
        /// <param name="id"></param>
        /// <param name="gids"></param>
        /// <returns></returns>
        public ActionResult RemoveUserGroups(int id, string gids)
        {
            string[]  ids = gids.Split(',');
            ClientApp app = ClientAppBll.GetById(id);

            if (app is null)
            {
                return(ResultData(null, false, "未找到应用!"));
            }

            List <UserGroup> groups = UserGroupBll.LoadEntities(u => ids.Contains(u.Id.ToString())).ToList();

            groups.ForEach(u => { app.UserGroup.Remove(u); });
            bool b = ClientAppBll.UpdateEntitySaved(app);

            return(ResultData(null, b, b ? "移除用户组成功!" : "移除用户组失败!"));
        }
Esempio n. 6
0
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <returns></returns>
        public ActionResult AddUsers(int id, string uids)
        {
            string[]  ids = uids.Split(',');
            ClientApp app = ClientAppBll.GetById(id);

            if (app is null)
            {
                return(ResultData(null, false, "未找到应用!"));
            }

            List <UserInfo> users = UserInfoBll.LoadEntities(u => ids.Contains(u.Id.ToString())).ToList();

            users.ForEach(u => { app.UserInfo.Add(u); });
            bool b = ClientAppBll.UpdateEntitySaved(app);

            return(ResultData(null, b, b ? "添加用户成功!" : "添加用户失败"));
        }
Esempio n. 7
0
        /// <summary>
        /// 修改子系统信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name">新名字</param>
        /// <returns></returns>
        public ActionResult Update(int id, string name)
        {
            ClientApp app = ClientAppBll.GetById(id);

            if (app != null)
            {
                if (ClientAppBll.Any(a => a.AppName.Equals(name) && !a.AppName.Equals(app.AppName)))
                {
                    return(ResultData(null, false, $"{name} 应用已经存在!"));
                }

                app.AppName = name;
                bool b = ClientAppBll.UpdateEntitySaved(app);
                return(ResultData(null, b, b ? "修改成功" : "修改失败!"));
            }

            return(ResultData(null, false, "未找到该应用程序!"));
        }
Esempio n. 8
0
        /// <summary>
        /// 切换应用的可用状态
        /// </summary>
        /// <param name="id">应用id</param>
        /// <param name="state">可用状态</param>
        /// <returns></returns>
        public ActionResult ToggleState(int id, bool state)
        {
            ClientApp app = ClientAppBll.GetById(id);

            if (app is null)
            {
                return(ResultData(null, false, "应用不存在!"));
            }

            if (app.Preset)
            {
                return(ResultData(null, false, "预置应用的状态不能修改!"));
            }

            app.Available = !state;
            bool b = ClientAppBll.UpdateEntitySaved(app);

            return(ResultData(null, b, b ? "状态切换成功!" : "状态切换失败!"));
        }
Esempio n. 9
0
        /// <summary>
        /// 添加或修改角色
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="RoleName">新名字</param>
        /// <param name="ParentId">父级组</param>
        /// <param name="appid">appid</param>
        /// <returns></returns>
        public ActionResult Save(int Id = 0, string RoleName = "", int?ParentId = null, string appid = "")
        {
            ParentId = ParentId == 0 ? null : ParentId;
            Role role = RoleBll.GetById(Id);

            if (role != null)
            {
                //修改
                if (RoleBll.Any(a => a.RoleName.Equals(RoleName) && !a.RoleName.Equals(role.RoleName)))
                {
                    return(ResultData(null, false, $"{RoleName} 角色已经存在!"));
                }

                role.RoleName = RoleName;
                role.ParentId = ParentId;
                bool b = RoleBll.UpdateEntitySaved(role);
                return(ResultData(null, b, b ? "修改成功" : "修改失败!"));
            }

            //添加
            if (RoleBll.Any(a => a.RoleName.Equals(RoleName)))
            {
                return(ResultData(null, false, $"{RoleName} 角色已经存在!"));
            }

            role = new Role()
            {
                RoleName = RoleName, ParentId = ParentId
            };
            if (!string.IsNullOrEmpty(appid) && ClientAppBll.Any(a => a.AppId.Equals(appid)))
            {
                var app = ClientAppBll.GetFirstEntity(a => a.AppId.Equals(appid));
                app.Roles.Add(role);
                bool b = ClientAppBll.UpdateEntitySaved(app);
                return(ResultData(null, b, b ? "角色添加成功!" : "角色添加失败!"));
            }

            role = RoleBll.AddEntitySaved(role);
            return(role != null?ResultData(role, true, "角色添加成功!") : ResultData(null, false, "角色添加失败!"));
        }
Esempio n. 10
0
        /// <summary>
        /// 添加或修改权限
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="PermissionName">新名字</param>
        /// <param name="ParentId">父级组</param>
        /// <param name="appid"></param>
        /// <returns></returns>
        public ActionResult Save(int Id = 0, string PermissionName = "", int?ParentId = null, string appid = "")
        {
            ParentId = ParentId == 0 ? null : ParentId;
            Permission permission = PermissionBll.GetById(Id);

            if (permission != null)
            {
                //修改
                if (PermissionBll.Any(a => a.PermissionName.Equals(PermissionName) && !a.PermissionName.Equals(permission.PermissionName)))
                {
                    return(ResultData(null, false, $"{PermissionName} 权限已经存在!"));
                }

                permission.PermissionName = PermissionName;
                permission.ParentId       = ParentId;
                bool b = PermissionBll.UpdateEntitySaved(permission);
                return(ResultData(null, b, b ? "修改成功" : "修改失败!"));
            }

            //添加
            if (PermissionBll.Any(a => a.PermissionName.Equals(PermissionName)))
            {
                return(ResultData(null, false, $"{PermissionName} 权限已经存在!"));
            }

            permission = new Permission {
                PermissionName = PermissionName, ParentId = ParentId
            };
            if (!string.IsNullOrEmpty(appid) && ClientAppBll.Any(a => a.AppId.Equals(appid)))
            {
                var app = ClientAppBll.GetFirstEntity(a => a.AppId.Equals(appid));
                app.Permissions.Add(permission);
                bool b = ClientAppBll.UpdateEntitySaved(app);
                return(ResultData(null, b, b ? "权限添加成功!" : "权限添加失败!"));
            }

            permission = PermissionBll.AddEntitySaved(permission);
            return(permission != null?ResultData(permission, true, "权限添加成功!") : ResultData(null, false, "权限添加失败!"));
        }