public IEnumerable <UserRoleEntity> GetRoleList(string userid) { var sql = PetaPoco.Sql.Builder.Append(@"select * from Base_UserRole where UserId=@0", userid); var list = Base_UserRole.Query(sql); return(EntityConvertTools.CopyToList <Base_UserRole, UserRoleEntity>(list.ToList())); }
public IEnumerable <UserRoleEntity> GetPageList(Pagination pagination, string queryJson) { var sql = PetaPoco.Sql.Builder.Append(@"select * from Base_UserRole where 1=1"); var queryParam = queryJson.ToJObject(); //查询条件 if (!queryParam["condition"].IsEmpty() && !queryParam["keyword"].IsEmpty()) { string condition = queryParam["condition"].ToString(); string keyword = queryParam["keyword"].ToString(); //switch (condition) //{ // case "EnCode": //岗位编号 // sql.Append(" and (charindex(@0,EnCode)>0)", keyword); // break; // case "FullName": //岗位名称 // sql.Append(" and (charindex(@0,FullName)>0)", keyword); // break; // default: // break; //} } if (!string.IsNullOrWhiteSpace(pagination.sidx)) { sql.OrderBy(new object[] { pagination.sidx + " " + pagination.sord }); } var currentpage = Base_UserRole.Page(pagination.page, pagination.rows, sql); //数据对象 var pageList = currentpage.Items; //分页对象 pagination.records = Converter.ParseInt32(currentpage.TotalItems); return(EntityConvertTools.CopyToList <Base_UserRole, UserRoleEntity>(pageList.ToList())); }
public IEnumerable <UserRoleEntity> GetList() { var sql = PetaPoco.Sql.Builder.Append(@"select * from Base_UserRole "); var list = Base_UserRole.Query(sql); return(EntityConvertTools.CopyToList <Base_UserRole, UserRoleEntity>(list.ToList())); }
/// <summary> /// 删除用户 /// </summary> /// <param name="keyValue">主键</param> public void RemoveForm(string keyValue) { using (var tran = QSDMS_SQLDB.GetInstance().GetTransaction()) { Base_User.Delete("where UserId=@0", keyValue); Base_UserRelation.Delete("where UserId=@0", keyValue); Base_UserRole.Delete("where UserId=@0", keyValue); Base_UserAuthorize.Delete("where UserId=@0", keyValue); tran.Complete(); } }
public void SaveForm(string keyValue, UserRoleEntity userRoleEntity) { if (!string.IsNullOrEmpty(keyValue)) { Base_UserRole role = Base_UserRole.SingleOrDefault("where UserRoleId=@0", keyValue); role = EntityConvertTools.CopyToModel <UserRoleEntity, Base_UserRole>(userRoleEntity, role); role.UserRoleId = keyValue; role.Update(); } else { Base_UserRole role = EntityConvertTools.CopyToModel <UserRoleEntity, Base_UserRole>(userRoleEntity, null); role.Insert(); } }
//动作:保存用户角色 // POST: /Sys/Base_User/Save_UserRoles public JsonResult Save_UserRoles(JObject data) { CommandResult cmdResult = CommandResult.Instance_Succeed; int UserId = data.Value <int>("userid"); var listUser = (data.Value <object>("crows") as JArray).ToList(); Base_UserRoleService.Instance.DeleteByWhere("and UserId=" + UserId); foreach (JObject item in listUser) { string RoleCode = item.Value <string>("RoleCode"); string RoleName = item.Value <string>("RoleName"); Base_UserRole obj = new Base_UserRole() { UserId = UserId, RoleCode = RoleCode }; bool exists = Base_UserRoleService.Instance.Exists_Fish("and UserId=" + UserId + " and RoleCode='" + RoleCode + "'"); var result = Base_UserRoleService.Instance.Insert(obj); if (result == 0) { cmdResult.ResultMsg += "用户角色[" + RoleName + "]插入失败"; } } return(JsonNet(cmdResult, JsonRequestBehavior.DenyGet)); }
public void RemoveForm(string keyValue) { Base_UserRole.Delete("where UserRoleId=@0", keyValue); }
public UserRoleEntity GetEntity(string keyValue) { var role = Base_UserRole.SingleOrDefault("where UserRoleId=@0", keyValue); return(EntityConvertTools.CopyToModel <Base_UserRole, UserRoleEntity>(role, null)); }
private bool Save(string roleguids) { string[] roleids = roleguids.Split(','); if (null == _userRoleList) { _userRoleList = new List<Base_UserRole>(); } Base_UserRole data; _userid = Request["fguid"]; for (int i = 0; i < roleids.Length - 1; i++) { data = new Base_UserRole(); data.Userid = _userid; data.Roleid = roleids[i]; _userRoleList.Add(data); } return _presenter.Save(); }
/// <summary> /// 保存用户表单(新增、修改) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="userEntity">用户实体</param> /// <returns></returns> public string SaveForm(string keyValue, UserEntity userEntity) { try { using (var tran = QSDMS_SQLDB.GetInstance().GetTransaction()) { #region 基本信息 if (!string.IsNullOrEmpty(keyValue)) { userEntity.Modify(keyValue); userEntity.Password = null; Base_User model = Base_User.SingleOrDefault("where UserId=@0", keyValue); model = EntityConvertTools.CopyToModel <UserEntity, Base_User>(userEntity, model); model.UserId = keyValue; model.Update(); } else { userEntity.Create(); keyValue = userEntity.UserId; userEntity.Secretkey = Md5Helper.MD5(CommonHelper.CreateNo(), 16).ToLower(); userEntity.Password = Md5Helper.MD5(DESEncrypt.Encrypt(userEntity.Password, userEntity.Secretkey).ToLower(), 32).ToLower(); userEntity.EnabledMark = 1; userEntity.DeleteMark = 0; Base_User model = EntityConvertTools.CopyToModel <UserEntity, Base_User>(userEntity, null); model.Insert(); } #endregion #region 默认添加 角色、岗位、职位 Base_UserRelation.Delete("where UserId=@0 and IsDefault=1", userEntity.UserId); List <UserRelationEntity> userRelationEntitys = new List <UserRelationEntity>(); //角色 这里多个角色逻辑处理 //if (!string.IsNullOrEmpty(userEntity.RoleId)) //{ // userRelationEntitys.Add(new UserRelationEntity // { // Category = (int)QSDMS.Model.Enums.UserCategoryEnum.角色, // UserRelationId = Guid.NewGuid().ToString(), // UserId = userEntity.UserId, // ObjectId = userEntity.RoleId, // CreateDate = DateTime.Now, // CreateUserId = OperatorProvider.Provider.Current().UserId, // CreateUserName = OperatorProvider.Provider.Current().UserName, // IsDefault = 1, // }); //} //一个用户多个角色 if (!string.IsNullOrEmpty(userEntity.RoleId)) { Base_UserRole.Delete("where UserId=@0", userEntity.UserId); string[] roles = userEntity.RoleId.Split(','); for (int i = 0; i < roles.Length; i++) { //用户角色表 string roleid = roles[i]; var userrole = new UserRoleEntity(); userrole.UserRoleId = Util.Util.NewUpperGuid(); userrole.UserId = userEntity.UserId; userrole.RoleId = roleid.Split('|')[0]; userrole.RoleName = roleid.Split('|')[1]; Base_UserRole model = EntityConvertTools.CopyToModel <UserRoleEntity, Base_UserRole>(userrole, null); model.Insert(); //用户关系表 userRelationEntitys.Add(new UserRelationEntity { Category = (int)QSDMS.Model.Enums.UserCategoryEnum.角色, UserRelationId = Guid.NewGuid().ToString(), UserId = userEntity.UserId, ObjectId = userrole.RoleId, CreateDate = DateTime.Now, CreateUserId = OperatorProvider.Provider.Current().UserId, CreateUserName = OperatorProvider.Provider.Current().UserName, IsDefault = 1, }); } } //岗位 if (!string.IsNullOrEmpty(userEntity.DutyId)) { userRelationEntitys.Add(new UserRelationEntity { Category = (int)QSDMS.Model.Enums.UserCategoryEnum.岗位, UserRelationId = Guid.NewGuid().ToString(), UserId = userEntity.UserId, ObjectId = userEntity.DutyId, CreateDate = DateTime.Now, CreateUserId = OperatorProvider.Provider.Current().UserId, CreateUserName = OperatorProvider.Provider.Current().UserName, IsDefault = 1, }); } //职位 if (!string.IsNullOrEmpty(userEntity.PostId)) { userRelationEntitys.Add(new UserRelationEntity { Category = (int)QSDMS.Model.Enums.UserCategoryEnum.职位, UserRelationId = Guid.NewGuid().ToString(), UserId = userEntity.UserId, ObjectId = userEntity.PostId, CreateDate = DateTime.Now, CreateUserId = OperatorProvider.Provider.Current().UserId, CreateUserName = OperatorProvider.Provider.Current().UserName, IsDefault = 1, }); } //插入用户关系表 foreach (UserRelationEntity userRelationItem in userRelationEntitys) { Base_UserRelation model = EntityConvertTools.CopyToModel <UserRelationEntity, Base_UserRelation>(userRelationItem, null); model.Insert(); } #endregion Base_UserAuthorize.Delete("where UserId=@0", userEntity.UserId); //插入用户对应数据权限 if (!string.IsNullOrEmpty(userEntity.AuthorizeDataId)) { string[] uthorizeDatas = userEntity.AuthorizeDataId.Split(','); for (int i = 0; i < uthorizeDatas.Length; i++) { string objectid = uthorizeDatas[i]; var userAuthorize = new UserAuthorizeEntity(); userAuthorize.UserAuthorizeId = Util.Util.NewUpperGuid(); userAuthorize.UserId = userEntity.UserId; userAuthorize.ObjectId = objectid.Split('|')[0]; userAuthorize.ObjectName = objectid.Split('|')[1]; Base_UserAuthorize model = EntityConvertTools.CopyToModel <UserAuthorizeEntity, Base_UserAuthorize>(userAuthorize, null); model.Insert(); } } tran.Complete(); } return(keyValue); } catch (Exception ex) { throw ex; } }