/// <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, "用户组添加失败!")); }