/// <summary> /// 过滤列表 /// </summary> /// <param name="condition"></param> /// <returns></returns> public IEnumerable <CUserGroup> Get(string condition) { var user = (CSign)HttpContext.Current.Session[ConfigurationManager.AppSettings["AuthSaveKey"]]; if (user == null) { throw new HttpResponseException(new SiginFailureMessage()); } using (var dal = DalBuilder.CreateDal(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString, 0)) { CUserGroup[] userGroups; try { dal.Open(); userGroups = UserGroupBll.Filter(dal, condition); dal.Close(); } catch (Exception ex) { LogBll.Write(dal, new CLog { LogUser = string.Format("{0}-{1}", user.UserCode, user.UserName), LogContent = string.Format("{0}#{1}", "UserGroup.Filter", ex.Message), LogType = LogType.系统异常 }); throw new HttpResponseException(new SystemExceptionMessage()); } if (userGroups == null) { throw new HttpResponseException(new DataNotFoundMessage()); } return(userGroups); } }
//add or edit protected void Button3_Click(object sender, EventArgs e) { id = BasePage.GetRequestId(Request.QueryString["id"]); UserGroupModel model = new UserGroupModel(); model.GroupName = txtGroupName.Text; model.ShowOnReg = int.Parse(txtShowOnReg.SelectedValue); model.Descript = txtDescript.Text; model.PowerList = GetChecked(this.PowerList, ","); model.id = id; if (id == 0) { int i = new UserGroupBll().Add(model); if (i > 0) { BasePage.JscriptPrint(Page, "添加成功!", "UserGroup.aspx"); } } else { bool bb = new UserGroupBll().Update(model); if (bb) { BasePage.JscriptPrint(Page, "修改成功!", "UserGroup.aspx"); } } }
//会员所在组名 protected string GetUserGroup(string id) { int idd = BasePage.GetRequestId(id); UserGroupModel model = new UserGroupBll().GetModel(idd); return(model.GroupName); }
/// <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="id"></param> /// <param name="page"></param> /// <param name="size"></param> /// <param name="kw"></param> /// <returns></returns> public ActionResult MyGroups(int id, int page = 1, int size = 10, string kw = "") { Expression <Func <UserGroup, bool> > where; Expression <Func <UserGroup, bool> > where2; if (!string.IsNullOrEmpty(kw)) { where = u => u.UserGroupRole.All(c => c.RoleId != id) && u.GroupName.Contains(kw); where2 = u => u.UserGroupRole.Any(c => c.RoleId == id) && u.GroupName.Contains(kw); } else { where = u => u.UserGroupRole.All(c => c.RoleId != id); where2 = u => u.UserGroupRole.Any(c => c.RoleId == id); } List <UserGroupOutputDto> not = UserGroupBll.LoadPageEntities <int, UserGroupOutputDto>(page, size, out int total1, where, u => u.Id, false).ToList(); //不属于该角色 List <UserGroup> list = UserGroupBll.LoadPageEntities(page, size, out int total2, where2, u => u.Id, false).ToList(); //属于该角色 List <UserGroupOutputDto> my = new List <UserGroupOutputDto>(); foreach (var p in list) { //判断有没有临时权限 UserGroupOutputDto per = p.Mapper <UserGroupOutputDto>(); per.HasRole = p.UserGroupRole.Any(u => u.RoleId.Equals(id) && u.UserGroupId == p.Id && u.HasRole); my.Add(per); } return(PageResult(new { my, not }, size, total1 >= total2 ? total1 : total2)); }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { ((Literal)Master.FindControl("breadcrumbs")).Text = "<a class=\"home\" href=\"UserGroup.aspx\">会员组管理</a><a class=\"add\" href=\"?action=Add\">添加新组</a>"; string checklogin = new AdminBll().CheckLogin("14"); if (checklogin != "true") { BasePage.Alertback(checklogin); Response.End(); } if (!String.IsNullOrEmpty(Request.QueryString["action"])) { action = Request.QueryString["action"]; } else { action = "show"; } id = BasePage.GetRequestId(Request.QueryString["id"]); if (!String.IsNullOrEmpty(Request.QueryString["id"])) { UserGroupModel model = new UserGroupBll().GetModel(id); bool b = new CommonBll().Exists(datatable, id); if (b) { Literal1.Text = "修改会员组"; Button3.Text = "确认修改"; txtGroupName.Text = model.GroupName; txtShowOnReg.Text = model.ShowOnReg.ToString(); txtDescript.Text = model.Descript; SetChecked(this.PowerList, model.PowerList, ","); } } else { DataSet ds = new DataSet(); int PageSize = 25; int PageIndex = BasePage.GetRequestId(Request.QueryString["Page"]); //当前第几页 ds = new CommonBll().GetListPage("", datatable, "", "id desc", PageSize, PageIndex); Repeater1.DataSource = ds; Repeater1.DataBind(); int totalrecord = new CommonBll().GetRecordCount(datatable, "");//总记录数 if (totalrecord == 0) { txtpage.Text = "<p align=\"center\">无相关信息</p>"; } else if (totalrecord > PageSize) { txtpage.Text = GL.Utility.GetPage.GetAspxPager(totalrecord, PageSize, PageIndex); } } } }
public async Task <IHttpActionResult> Userinfo() { JsonResult <UserinfoViewModel> result = new JsonResult <UserinfoViewModel>(); result.code = 1; result.msg = "OK"; await Task.Run(() => { ApiUserManager userManager = new ApiUserManager(ActionContext); UserinfoViewModel uv = new UserinfoViewModel(); uv.Age = "0"; if (userManager.User.BirthDate != DateTime.MaxValue && userManager.User.BirthDate != DateTime.MinValue) { uv.Age = (DateTime.Now.Year - userManager.User.BirthDate.Year).TryToString(); } uv.BirthDate = userManager.User.BirthDate.ToString("yyyy-MM-dd"); uv.city = userManager.User.city; uv.Email = userManager.User.Email; uv.EnterpriseID = userManager.User.EnterpriseID; uv.GroupID = userManager.User.GroupID; if (!uv.GroupID.IsNull()) { UserGroupBll groupbll = new UserGroupBll(); var group = groupbll.GetByID(uv.GroupID); if (group != null) { uv.GroupName = group.GroupName; } } uv.Headimgurl = userManager.User.Headimgurl; uv.ID = userManager.User.ID; uv.IsAdmin = userManager.User.IsAdmin; uv.IsHighestAdmin = userManager.User.IsHighestAdmin; uv.IsSystemAdmin = userManager.User.IsSystemAdmin; uv.Name = userManager.User.Name; uv.Nickname = userManager.User.Nickname; uv.province = userManager.User.province; uv.Residence = userManager.User.Residence; uv.Sex = ((int)userManager.User.Sex).TryToString(); uv.Telephone = userManager.User.Telephone; uv.UserName = userManager.User.UserName; uv.Openid = userManager.User.Openid; if (!userManager.User.IDNum.IsNull()) { uv.IDNum = $"{userManager.User.IDNum.Substring(0, 4)}**********{userManager.User.IDNum.Substring(14)}"; } result.Result = uv; }); return(Ok(result)); }
/// <summary> /// 获取用户组分页数据 /// </summary> /// <param name="appid">appid</param> /// <param name="page"></param> /// <param name="size"></param> /// <returns></returns> public ActionResult PageData(string appid, int page = 1, int size = 10) { var where = string.IsNullOrEmpty(appid) ? (Expression <Func <UserGroup, bool> >)(g => true) : (g => g.ClientApp.Any(a => a.AppId.Equals(appid))); List <int> ids = UserGroupBll.LoadPageEntitiesNoTracking <int, UserGroupOutputDto>(page, size, out int total, where, a => a.Id, false).Select(g => g.Id).ToList(); List <UserGroupOutputDto> list = new List <UserGroupOutputDto>(); ids.ForEach(g => { List <UserGroupOutputDto> temp = UserGroupBll.GetSelfAndChildrenByParentId(g).ToList(); list.AddRange(temp); }); return(PageResult(list.DistinctBy(u => u.Id), size, total)); }
// GET api/userselecterapi public IEnumerable <CLenovoInputOption> Get(string dataSource, string condition) { var user = (CSign)HttpContext.Current.Session[ConfigurationManager.AppSettings["AuthSaveKey"]]; if (user == null) { throw new HttpResponseException(new SiginFailureMessage()); } using (var dal = DalBuilder.CreateDal(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString, 0)) { CLenovoInputOption[] options; try { dal.Open(); switch (dataSource) { case "User": options = UserBll.GetLenovoInputOption(dal, condition); break; case "Dept": options = DeptBll.GetLenovoInputOption(dal, condition); break; case "UserGroup": options = UserGroupBll.GetLenovoInputOption(dal, condition); break; default: throw new HttpResponseException(new SystemExceptionMessage()); } dal.Close(); } catch (Exception ex) { LogBll.Write(dal, new CLog { LogUser = string.Format("{0}-{1}", user.UserCode, user.UserName), LogContent = string.Format("{0}#{1}", "LenovoInputer.List", ex.Message), LogType = LogType.系统异常 }); throw new HttpResponseException(new SystemExceptionMessage()); } if (options == null) { throw new HttpResponseException(new DataNotFoundMessage()); } return(options); } }
// POST api/usergroupapi public CUserGroup Post(CUserGroup value) { var user = (CSign)HttpContext.Current.Session[ConfigurationManager.AppSettings["AuthSaveKey"]]; if (user == null) { throw new HttpResponseException(new SiginFailureMessage()); } using (var dal = DalBuilder.CreateDal(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString, 0)) { bool ok; try { dal.Open(); ok = UserGroupBll.Create(dal, value, string.Format("{0}-{1}", user.UserCode, user.UserName)); } catch (Exception ex) { if (ex.Message.StartsWith("违反了 UNIQUE KEY 约束")) { throw new HttpResponseException(new PrimaryRepeatedMessge()); } LogBll.Write(dal, new CLog { LogUser = string.Format("{0}-{1}", user.UserCode, user.UserName), LogContent = string.Format("{0}#{1}", "UserGroup.Post", ex.Message), LogType = LogType.系统异常 }); throw new HttpResponseException(new SystemExceptionMessage()); } if (!ok) { LogBll.Write(dal, new CLog { LogUser = string.Format("{0}-{1}", user.UserCode, user.UserName), LogContent = string.Format("新建用户组{0}-{1}", value.GroupCode, value.GroupName), LogType = LogType.操作失败 }); throw new HttpResponseException(new DealFailureMessage()); } LogBll.Write(dal, new CLog { LogUser = string.Format("{0}-{1}", user.UserCode, user.UserName), LogContent = string.Format("新建用户组{0}-{1}", value.GroupCode, value.GroupName), LogType = LogType.操作成功 }); dal.Close(); return(value); } }
// DELETE api/usergroupapi/5 public void Delete(int id) { var user = (CSign)HttpContext.Current.Session[ConfigurationManager.AppSettings["AuthSaveKey"]]; if (user == null) { throw new HttpResponseException(new SiginFailureMessage()); } using (var dal = DalBuilder.CreateDal(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString, 0)) { bool ok; CUserGroup hisUserGroup; try { dal.Open(); ok = UserGroupBll.Delete(dal, id, out hisUserGroup); } catch (Exception ex) { LogBll.Write(dal, new CLog { LogUser = string.Format("{0}-{1}", user.UserCode, user.UserName), LogContent = string.Format("{0}#{1}", "UserGroup.Delete", ex.Message), LogType = LogType.系统异常 }); throw new HttpResponseException(new SystemExceptionMessage()); } if (!ok) { if (hisUserGroup != null) { LogBll.Write(dal, new CLog { LogUser = string.Format("{0}-{1}", user.UserCode, user.UserName), LogContent = string.Format("删除用户组{0}-{1}", hisUserGroup.GroupCode, hisUserGroup.GroupName), LogType = LogType.操作失败 }); } throw new HttpResponseException(new DealFailureMessage()); } LogBll.Write(dal, new CLog { LogUser = string.Format("{0}-{1}", user.UserCode, user.UserName), LogContent = string.Format("新建用户组{0}-{1}", hisUserGroup.GroupCode, hisUserGroup.GroupName), LogType = LogType.操作成功 }); dal.Close(); } }
/// <summary> /// 获取应用所有的用户组 /// </summary> /// <param name="appid"></param> /// <param name="kw">查询关键词</param> /// <returns></returns> public ActionResult GetAll(string appid, string kw) { var where = string.IsNullOrEmpty(appid) ? (Expression <Func <UserGroup, bool> >)(g => true) : (g => g.ClientApp.Any(a => a.AppId.Equals(appid))); UserGroupBll.LoadEntitiesNoTracking <UserGroupOutputDto>(where); List <int> ids = UserGroupBll.LoadEntitiesNoTracking <UserGroupOutputDto>(where).Select(g => g.Id).ToList(); List <UserGroupOutputDto> list = new List <UserGroupOutputDto>(); ids.ForEach(g => { var raw = UserGroupBll.GetSelfAndChildrenByParentId(g); var temp = string.IsNullOrEmpty(kw) ? raw.ToList() : raw.Where(u => u.GroupName.Contains(kw)).ToList(); list.AddRange(temp); }); return(ResultData(list.DistinctBy(u => u.Id))); }
/// <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 ? "移除用户组成功!" : "移除用户组失败!")); }
/// <summary> /// 从应用移除用户 /// </summary> /// <param name="id"></param> /// <param name="uids"></param> /// <returns></returns> public ActionResult RemoveUsers(int id, string uids) { string[] ids = uids.Split(','); UserGroup @group = UserGroupBll.GetById(id); if (@group is null) { return(ResultData(null, false, "未找到用户组!")); } List <UserInfo> users = UserInfoBll.LoadEntities(u => ids.Contains(u.Id.ToString())).ToList(); users.ForEach(u => { @group.UserInfo.Remove(u); }); bool b = UserGroupBll.UpdateEntitySaved(@group); return(ResultData(null, b, b ? "移除用户成功!" : "移除用户失败!")); }
/// <summary> /// 移除用户组 /// </summary> /// <param name="id">用户id</param> /// <param name="gids">用户组id</param> /// <returns></returns> public ActionResult RemoveGroups(Guid id, string gids) { string[] ids = gids.Split(','); UserInfo user = UserInfoBll.GetById(id); if (user is null) { return(ResultData(null, false, "未找到用户!")); } List <UserGroup> groups = UserGroupBll.LoadEntities(g => ids.Contains(g.Id.ToString())).ToList(); groups.ForEach(g => user.UserGroup.Remove(g)); bool b = UserInfoBll.UpdateEntitySaved(user); return(ResultData(null, b, b ? "移除用户组完成!" : "移除用户组失败!")); }
/// <summary> /// 从应用移除用户 /// </summary> /// <param name="id"></param> /// <param name="aids"></param> /// <returns></returns> public ActionResult RemoveApps(int id, string aids) { string[] ids = aids.Split(','); UserGroup @group = UserGroupBll.GetById(id); if (@group is null) { return(ResultData(null, false, "未找到用户组!")); } List <ClientApp> users = ClientAppBll.LoadEntities(u => ids.Contains(u.Id.ToString())).ToList(); users.ForEach(u => { @group.ClientApp.Remove(u); }); bool b = UserGroupBll.UpdateEntitySaved(@group); return(ResultData(null, b, b ? "移除客户端子系统成功!" : "移除客户端子系统失败!")); }
/// <summary> /// 改变父级组 /// </summary> /// <param name="id"></param> /// <param name="pid"></param> /// <returns></returns> public ActionResult ChangeParent(int id, int?pid) { UserGroup @group = UserGroupBll.GetById(id); if (pid.HasValue) { UserGroup parent = UserGroupBll.GetById(pid); if (parent is null) { pid = null; } } group.ParentId = pid; bool b = UserGroupBll.UpdateEntitySaved(@group); return(ResultData(null, b, b ? "父级指派成功!" : "父级指派失败!")); }
public IEnumerable <UserGroup> Get(int page) { var httpCookie = HttpContext.Current.Request.Cookies["Retailer"]; if (httpCookie == null) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NonAuthoritativeInformation)); } var tooken = httpCookie.Value; try { return(UserGroupBll.Get(page, 10)); } catch { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)); } }
/// <summary> /// 添加用户组 /// </summary> /// <param name="id">角色id</param> /// <param name="gids">用户组id集合</param> /// <returns></returns> public ActionResult AddGroups(int id, string gids) { string[] ids = gids.Split(','); Role role = RoleBll.GetById(id); if (role is null) { return(ResultData(null, false, "未找到相应的角色信息!")); } List <UserGroup> groups = UserGroupBll.LoadEntities(g => ids.Contains(g.Id.ToString())).ToList(); groups.ForEach(g => UserGroupRoleBll.AddEntity(new UserGroupRole() { UserGroup = g, Role = role, HasRole = true, RoleId = role.Id, UserGroupId = g.Id })); bool b = UserGroupRoleBll.SaveChanges() > 0; return(ResultData(null, b, b ? "角色配置完成!" : "角色配置失败!")); }
/// <summary> /// 获取该应用的用户组 /// </summary> /// <param name="id"></param> /// <param name="page"></param> /// <param name="size"></param> /// <param name="kw"></param> /// <returns></returns> public ActionResult MyGroups(int id, int page = 1, int size = 10, string kw = "") { Expression <Func <UserGroup, bool> > where; Expression <Func <UserGroup, bool> > where2; if (!string.IsNullOrEmpty(kw)) { where = u => u.ClientApp.All(c => c.Id != id) && u.GroupName.Contains(kw); where2 = u => u.ClientApp.Any(c => c.Id == id) && u.GroupName.Contains(kw); } else { where = u => u.ClientApp.All(c => c.Id != id); where2 = u => u.ClientApp.Any(c => c.Id == id); } List <UserGroupOutputDto> not = UserGroupBll.LoadPageEntities <int, UserGroupOutputDto>(page, size, out int total1, where, u => u.Id, false).ToList(); //不属于该应用 List <UserGroupOutputDto> my = UserGroupBll.LoadPageEntities <int, UserGroupOutputDto>(page, size, out int total2, where2, u => u.Id, false).ToList(); //属于该应用 return(PageResult(new { my, not }, size, total1 >= total2 ? total1 : total2)); }
/// <summary> /// 获取用户组详情 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Details(int id) { UserGroup @group = UserGroupBll.GetById(id); if (@group != null) { (IQueryable <ClientApp>, IQueryable <UserInfo>, List <UserGroup>, List <UserGroupRole>, List <Permission>, List <Control>, List <Menu>)details = UserGroupBll.Details(@group); return(ResultData(new { result = group.Mapper <UserGroupOutputDto>(), apps = details.Item1.ToList().Mapper <List <ClientAppInputDto> >(), groups = details.Item3.Mapper <List <UserGroupInputDto> >(), roles_allow = details.Item4.Where(g => g.HasRole).Select(g => g.Role).Mapper <List <RoleInputDto> >(), roles_forbid = details.Item4.Where(g => !g.HasRole).Select(g => g.Role).Mapper <List <RoleInputDto> >(), permissions = details.Item5.Mapper <List <PermissionInputDto> >(), controls = details.Item6.Mapper <List <ControlOutputDto> >(), menus = details.Item7.Mapper <List <MenuOutputDto> >() })); } return(ResultData(null, false, "用户组不存在")); }
/// <summary> /// 添加角色 /// </summary> /// <param name="id">用户组id</param> /// <param name="rids">角色id</param> /// <returns></returns> public ActionResult AddRoles(int id, string rids) { string[] ids = rids.Split(','); var @group = UserGroupBll.GetById(id); if (group is null) { return(ResultData(null, false, "用户组不存在")); } List <Role> roles = RoleBll.LoadEntities(r => ids.Contains(r.Id.ToString())).ToList(); roles.ForEach(r => { UserGroupRole groupRole = new UserGroupRole() { UserGroupId = @group.Id, HasRole = true, RoleId = r.Id, Role = r, UserGroup = @group }; UserGroupRoleBll.AddEntity(groupRole); }); UserGroupRoleBll.BulkSaveChanges(); return(ResultData(null, true, "角色配置完成!")); }
/// <summary> /// 获取用户组详情 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Get(int id) { UserGroupOutputDto group = UserGroupBll.GetById(id).Mapper <UserGroupOutputDto>(); return(ResultData(group)); }
public UserController(UserBll userBll, UserGroupBll userGroupBll, LogBll logBll) { _userBll = userBll; _userGroupBll = userGroupBll; _logBll = logBll; }
public SystemSetupController(UserGroupBll _userGroupBll, LoginLogBll _loginLogBll, OperationLogBll _operationBll) { userGroupBll = _userGroupBll; loginLogBll = _loginLogBll; operationBll = _operationBll; }
/// <summary> /// 删除用户组 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Delete(int id) { bool b = UserGroupBll.DeleteByIdSaved(id); return(ResultData(null, b, b ? "用户组删除成功!" : "用户组删除失败!")); }