public IHttpActionResult Submit([FromBody] UserMenuInfo menuInfo) { try { var request = new AuthenticatedRequest(); if (!request.IsAdminLoggin || !request.AdminPermissionsImpl.HasSystemPermissions(ConfigManager.AppPermissions.SettingsConfigHomeMenu)) { return(Unauthorized()); } if (menuInfo.Id == 0) { DataProvider.UserMenuDao.Insert(menuInfo); request.AddAdminLog("新增用户菜单", $"用户菜单:{menuInfo.Text}"); } else if (menuInfo.Id > 0) { DataProvider.UserMenuDao.Update(menuInfo); request.AddAdminLog("修改用户菜单", $"用户菜单:{menuInfo.Text}"); } return(Ok(new { Value = UserMenuManager.GetAllUserMenuInfoList() })); } catch (Exception ex) { return(InternalServerError(ex)); } }
public void Update(UserMenuInfo menuInfo) { var sqlString = $@"UPDATE {TableName} SET {nameof(UserMenuInfo.SystemId)} = @{nameof(UserMenuInfo.SystemId)}, {nameof(UserMenuInfo.GroupIdCollection)} = @{nameof(UserMenuInfo.GroupIdCollection)}, {nameof(UserMenuInfo.IsDisabled)} = @{nameof(UserMenuInfo.IsDisabled)}, {nameof(UserMenuInfo.ParentId)} = @{nameof(UserMenuInfo.ParentId)}, {nameof(UserMenuInfo.Taxis)} = @{nameof(UserMenuInfo.Taxis)}, {nameof(UserMenuInfo.Text)} = @{nameof(UserMenuInfo.Text)}, {nameof(UserMenuInfo.IconClass)} = @{nameof(UserMenuInfo.IconClass)}, {nameof(UserMenuInfo.Href)} = @{nameof(UserMenuInfo.Href)}, {nameof(UserMenuInfo.Target)} = @{nameof(UserMenuInfo.Target)} WHERE {nameof(UserMenuInfo.Id)} = @{nameof(UserMenuInfo.Id)}"; IDataParameter[] parameters = { GetParameter(nameof(UserMenuInfo.SystemId), DataType.VarChar, 50, menuInfo.SystemId), GetParameter(nameof(UserMenuInfo.GroupIdCollection), DataType.VarChar, 200, menuInfo.GroupIdCollection), GetParameter(nameof(UserMenuInfo.IsDisabled), DataType.Boolean, menuInfo.IsDisabled), GetParameter(nameof(UserMenuInfo.ParentId), DataType.Integer, menuInfo.ParentId), GetParameter(nameof(UserMenuInfo.Taxis), DataType.Integer, menuInfo.Taxis), GetParameter(nameof(UserMenuInfo.Text), DataType.VarChar, 50, menuInfo.Text), GetParameter(nameof(UserMenuInfo.IconClass), DataType.VarChar, 50, menuInfo.IconClass), GetParameter(nameof(UserMenuInfo.Href), DataType.VarChar, 200, menuInfo.Href), GetParameter(nameof(UserMenuInfo.Target), DataType.VarChar, 50, menuInfo.Target), GetParameter(nameof(UserMenuInfo.Id), DataType.Integer, menuInfo.Id) }; ExecuteNonQuery(sqlString, parameters); UserMenuManager.ClearCache(); }
public UserMenuInfo GetModel(Guid userId, Guid menuId) { UserMenuInfo model = null; StringBuilder sb = new StringBuilder(300); sb.Append(@"select top 1 UserId,MenuId,OperationAccess from UserMenu where UserId = @UserId and MenuId = @MenuId " ); SqlParameter[] parms = { new SqlParameter("@UserId", SqlDbType.UniqueIdentifier), new SqlParameter("@MenuId", SqlDbType.UniqueIdentifier) }; parms[0].Value = userId; parms[1].Value = menuId; using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.AssetConnString, CommandType.Text, sb.ToString(), parms)) { if (reader != null) { if (reader.Read()) { model = new UserMenuInfo(); model.UserId = reader.GetGuid(0); model.MenuId = reader.GetGuid(1); model.OperationAccess = reader.GetString(2); } } } return(model); }
public IList <UserMenuInfo> GetList() { StringBuilder sb = new StringBuilder(300); sb.Append(@"select UserId,MenuId,OperationAccess from UserMenu order by LastUpdatedDate desc " ); IList <UserMenuInfo> list = new List <UserMenuInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.AssetConnString, CommandType.Text, sb.ToString())) { if (reader != null && reader.HasRows) { while (reader.Read()) { UserMenuInfo model = new UserMenuInfo(); model.UserId = reader.GetGuid(0); model.MenuId = reader.GetGuid(1); model.OperationAccess = reader.GetString(2); list.Add(model); } } } return(list); }
public IList <UserMenuInfo> GetList(string sqlWhere, params SqlParameter[] cmdParms) { StringBuilder sb = new StringBuilder(500); sb.Append(@"select UserId,MenuId,OperationAccess from UserMenu "); if (!string.IsNullOrEmpty(sqlWhere)) { sb.AppendFormat(" where 1=1 {0} ", sqlWhere); } IList <UserMenuInfo> list = new List <UserMenuInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.AssetConnString, CommandType.Text, sb.ToString(), cmdParms)) { if (reader != null && reader.HasRows) { while (reader.Read()) { UserMenuInfo model = new UserMenuInfo(); model.UserId = reader.GetGuid(0); model.MenuId = reader.GetGuid(1); model.OperationAccess = reader.GetString(2); list.Add(model); } } } return(list); }
public IList <UserMenuInfo> GetList(int pageIndex, int pageSize, string sqlWhere, params SqlParameter[] cmdParms) { StringBuilder sb = new StringBuilder(500); int startIndex = (pageIndex - 1) * pageSize + 1; int endIndex = pageIndex * pageSize; sb.Append(@"select * from(select row_number() over(order by LastUpdatedDate desc) as RowNumber, UserId,MenuId,OperationAccess from UserMenu " ); if (!string.IsNullOrEmpty(sqlWhere)) { sb.AppendFormat(" where 1=1 {0} ", sqlWhere); } sb.AppendFormat(@")as objTable where RowNumber between {0} and {1} ", startIndex, endIndex); IList <UserMenuInfo> list = new List <UserMenuInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.AssetConnString, CommandType.Text, sb.ToString(), cmdParms)) { if (reader != null && reader.HasRows) { while (reader.Read()) { UserMenuInfo model = new UserMenuInfo(); model.UserId = reader.GetGuid(1); model.MenuId = reader.GetGuid(2); model.OperationAccess = reader.GetString(3); list.Add(model); } } } return(list); }
public int Insert(UserMenuInfo menuInfo) { var sqlString = $@" INSERT INTO {TableName} ( {nameof(UserMenuInfo.SystemId)}, {nameof(UserMenuInfo.GroupIdCollection)}, {nameof(UserMenuInfo.IsDisabled)}, {nameof(UserMenuInfo.ParentId)}, {nameof(UserMenuInfo.Taxis)}, {nameof(UserMenuInfo.Text)}, {nameof(UserMenuInfo.IconClass)}, {nameof(UserMenuInfo.Href)}, {nameof(UserMenuInfo.Target)} ) VALUES ( @{nameof(UserMenuInfo.SystemId)}, @{nameof(UserMenuInfo.GroupIdCollection)}, @{nameof(UserMenuInfo.IsDisabled)}, @{nameof(UserMenuInfo.ParentId)}, @{nameof(UserMenuInfo.Taxis)}, @{nameof(UserMenuInfo.Text)}, @{nameof(UserMenuInfo.IconClass)}, @{nameof(UserMenuInfo.Href)}, @{nameof(UserMenuInfo.Target)} )"; var parms = new IDataParameter[] { GetParameter($"@{nameof(UserMenuInfo.SystemId)}", DataType.VarChar, 50, menuInfo.SystemId), GetParameter($"@{nameof(UserMenuInfo.GroupIdCollection)}", DataType.VarChar, 200, menuInfo.GroupIdCollection), GetParameter($"@{nameof(UserMenuInfo.IsDisabled)}", DataType.Boolean, menuInfo.IsDisabled), GetParameter($"@{nameof(UserMenuInfo.ParentId)}", DataType.Integer, menuInfo.ParentId), GetParameter($"@{nameof(UserMenuInfo.Taxis)}", DataType.Integer, menuInfo.Taxis), GetParameter($"@{nameof(UserMenuInfo.Text)}", DataType.VarChar, 50, menuInfo.Text), GetParameter($"@{nameof(UserMenuInfo.IconClass)}", DataType.VarChar, 50, menuInfo.IconClass), GetParameter($"@{nameof(UserMenuInfo.Href)}", DataType.VarChar, 200, menuInfo.Href), GetParameter($"@{nameof(UserMenuInfo.Target)}", DataType.VarChar, 50, menuInfo.Target) }; var menuId = ExecuteNonQueryAndReturnId(TableName, nameof(UserMenuInfo.Id), sqlString, parms); UserMenuManager.ClearCache(); return(menuId); }
public int Update(UserMenuInfo model) { StringBuilder sb = new StringBuilder(250); sb.Append(@"update UserMenu set OperationAccess = @OperationAccess where UserId = @UserId and MenuId = @MenuId " ); SqlParameter[] parms = { new SqlParameter("@UserId", SqlDbType.UniqueIdentifier), new SqlParameter("@MenuId", SqlDbType.UniqueIdentifier), new SqlParameter("@OperationAccess", SqlDbType.VarChar, 300) }; parms[0].Value = model.UserId; parms[1].Value = model.MenuId; parms[2].Value = model.OperationAccess; return(SqlHelper.ExecuteNonQuery(SqlHelper.AssetConnString, CommandType.Text, sb.ToString(), parms)); }
public int Insert(UserMenuInfo model) { StringBuilder sb = new StringBuilder(250); sb.Append(@"insert into UserMenu (UserId,MenuId,OperationAccess) values (@UserId,@MenuId,@OperationAccess) " ); SqlParameter[] parms = { new SqlParameter("@UserId", SqlDbType.UniqueIdentifier), new SqlParameter("@MenuId", SqlDbType.UniqueIdentifier), new SqlParameter("@OperationAccess", SqlDbType.VarChar, 300) }; parms[0].Value = model.UserId; parms[1].Value = model.MenuId; parms[2].Value = model.OperationAccess; return(SqlHelper.ExecuteNonQuery(SqlHelper.AssetConnString, CommandType.Text, sb.ToString(), parms)); }
public ResResultModel SaveRoleMenu(RoleMenuFmModel model) { try { if (model == null) { return(ResResult.Response(false, MC.Request_Params_InvalidError, "")); } if (string.IsNullOrWhiteSpace(model.MenuItemJson)) { return(ResResult.Response(false, MC.Request_Params_InvalidError, "")); } model.MenuItemJson = HttpUtility.UrlDecode(model.MenuItemJson); if (string.IsNullOrWhiteSpace(model.RoleName) && string.IsNullOrWhiteSpace(model.UserName)) { return(ResResult.Response(false, MC.Request_Params_InvalidError, "")); } List <RoleMenuFmInfo> list = JsonConvert.DeserializeObject <List <RoleMenuFmInfo> >(model.MenuItemJson); string roleId = ""; string userId = ""; var isRole = !string.IsNullOrWhiteSpace(model.RoleName); RoleMenu roleMenuBll = null; UserMenu userMenuBll = null; if (isRole) { roleMenuBll = new RoleMenu(); var roleBll = new Role(); var roleModel = roleBll.GetModel(model.RoleName); if (roleModel == null) { return(ResResult.Response(false, MC.GetString(MC.Request_NotExist, "角色'" + model.RoleName + "'对应数据"), "")); } roleId = roleModel.RoleId.ToString(); } else { userMenuBll = new UserMenu(); userId = Membership.GetUser(model.UserName).ProviderUserKey.ToString(); } var menuBll = new Menus(); foreach (var item in list) { var menuModel = menuBll.GetModel(Guid.Parse(item.MenuId.ToString())); menuModel.AllowRoles = menuModel.AllowRoles.Replace("*", ""); var isChanged = false; var isAccessChanged = false; var isInsert = false; var apaItems = new List <string>(); if (isRole) { var roleMenuModel = roleMenuBll.GetModel(Guid.Parse(roleId), Guid.Parse(item.MenuId.ToString())); if (roleMenuModel == null) { isInsert = true; roleMenuModel = new RoleMenuInfo(); roleMenuModel.RoleId = Guid.Parse(roleId); roleMenuModel.MenuId = Guid.Parse(item.MenuId.ToString()); } if (!string.IsNullOrEmpty(roleMenuModel.OperationAccess)) { apaItems = roleMenuModel.OperationAccess.Split(',').ToList(); } #region 允许角色 if (item.IsView) { if (!menuModel.AllowRoles.Contains(roleId)) { var allowRoles = menuModel.AllowRoles.Split(',').ToList(); allowRoles.Add(roleId); menuModel.AllowRoles = string.Join(",", allowRoles.ToArray()).Trim(','); isChanged = true; } } else { if (menuModel.AllowRoles.Contains(roleId)) { var allowRoles = menuModel.AllowRoles.Split(',').ToList(); allowRoles.Remove(roleId); if (allowRoles.Count > 0) { menuModel.AllowRoles = string.Join(",", allowRoles.ToArray()).Trim(','); } else { menuModel.AllowRoles = ""; } isChanged = true; } } #endregion #region 角色其它权限 if (item.IsAdd) { if (!apaItems.Contains(((int)EnumData.EnumOperationAccess.新增).ToString())) { apaItems.Add(((int)EnumData.EnumOperationAccess.新增).ToString()); roleMenuModel.OperationAccess = string.Join(",", apaItems.ToArray()).Trim(','); isAccessChanged = true; } } else { if (apaItems.Contains(((int)EnumData.EnumOperationAccess.新增).ToString())) { apaItems.Remove(((int)EnumData.EnumOperationAccess.新增).ToString()); isAccessChanged = true; if (apaItems.Count > 0) { roleMenuModel.OperationAccess = string.Join(",", apaItems.ToArray()).Trim(','); } else { roleMenuModel.OperationAccess = ""; } } } if (item.IsDelete) { if (!apaItems.Contains(((int)EnumData.EnumOperationAccess.除).ToString())) { apaItems.Add(((int)EnumData.EnumOperationAccess.除).ToString()); roleMenuModel.OperationAccess = string.Join(",", apaItems.ToArray()).Trim(','); isAccessChanged = true; } } else { if (apaItems.Contains(((int)EnumData.EnumOperationAccess.除).ToString())) { apaItems.Remove(((int)EnumData.EnumOperationAccess.除).ToString()); isAccessChanged = true; if (apaItems.Count > 0) { roleMenuModel.OperationAccess = string.Join(",", apaItems.ToArray()).Trim(','); } else { roleMenuModel.OperationAccess = ""; } } } if (item.IsEdit) { if (!apaItems.Contains(((int)EnumData.EnumOperationAccess.编辑).ToString())) { apaItems.Add(((int)EnumData.EnumOperationAccess.编辑).ToString()); roleMenuModel.OperationAccess = string.Join(",", apaItems.ToArray()).Trim(','); isAccessChanged = true; } } else { if (apaItems.Contains(((int)EnumData.EnumOperationAccess.编辑).ToString())) { apaItems.Remove(((int)EnumData.EnumOperationAccess.编辑).ToString()); isAccessChanged = true; if (apaItems.Count > 0) { roleMenuModel.OperationAccess = string.Join(",", apaItems.ToArray()).Trim(','); } else { roleMenuModel.OperationAccess = ""; } } } #endregion if (isAccessChanged) { if (isInsert) { roleMenuBll.Insert(roleMenuModel); } else { roleMenuBll.Update(roleMenuModel); } } } else { var userMenuInfo = userMenuBll.GetModel(Guid.Parse(userId), Guid.Parse(item.MenuId.ToString())); if (userMenuInfo == null) { isInsert = true; userMenuInfo = new UserMenuInfo(); userMenuInfo.UserId = Guid.Parse(userId); userMenuInfo.MenuId = Guid.Parse(item.MenuId.ToString()); } if (!string.IsNullOrEmpty(userMenuInfo.OperationAccess)) { apaItems = userMenuInfo.OperationAccess.Split(',').ToList(); } #region 拒绝用户 if (item.IsView) { if (!menuModel.DenyUsers.Contains(userId)) { var denyUsers = menuModel.DenyUsers.Split(',').ToList(); denyUsers.Add(userId); menuModel.DenyUsers = string.Join(",", denyUsers.ToArray()).Trim(','); isChanged = true; } } else { if (menuModel.DenyUsers.Contains(userId)) { var denyUsers = menuModel.DenyUsers.Split(',').ToList(); denyUsers.Remove(userId); if (denyUsers.Count > 0) { menuModel.DenyUsers = string.Join(",", denyUsers.ToArray()).Trim(','); } else { menuModel.DenyUsers = ""; } isChanged = true; } } #endregion #region 拒绝用户其它权限 if (item.IsAdd) { if (!apaItems.Contains(((int)EnumData.EnumOperationAccess.新增).ToString())) { apaItems.Add(((int)EnumData.EnumOperationAccess.新增).ToString()); userMenuInfo.OperationAccess = string.Join(",", apaItems.ToArray()).Trim(','); isAccessChanged = true; } } else { if (apaItems.Contains(((int)EnumData.EnumOperationAccess.新增).ToString())) { apaItems.Remove(((int)EnumData.EnumOperationAccess.新增).ToString()); isAccessChanged = true; if (apaItems.Count > 0) { userMenuInfo.OperationAccess = string.Join(",", apaItems.ToArray()).Trim(','); } else { userMenuInfo.OperationAccess = ""; } } } if (item.IsDelete) { if (!apaItems.Contains(((int)EnumData.EnumOperationAccess.除).ToString())) { apaItems.Add(((int)EnumData.EnumOperationAccess.除).ToString()); userMenuInfo.OperationAccess = string.Join(",", apaItems.ToArray()).Trim(','); isAccessChanged = true; } } else { if (apaItems.Contains(((int)EnumData.EnumOperationAccess.除).ToString())) { apaItems.Remove(((int)EnumData.EnumOperationAccess.除).ToString()); isAccessChanged = true; if (apaItems.Count > 0) { userMenuInfo.OperationAccess = string.Join(",", apaItems.ToArray()).Trim(','); } else { userMenuInfo.OperationAccess = ""; } } } if (item.IsEdit) { if (!apaItems.Contains(((int)EnumData.EnumOperationAccess.编辑).ToString())) { apaItems.Add(((int)EnumData.EnumOperationAccess.编辑).ToString()); userMenuInfo.OperationAccess = string.Join(",", apaItems.ToArray()).Trim(','); isAccessChanged = true; } } else { if (apaItems.Contains(((int)EnumData.EnumOperationAccess.编辑).ToString())) { apaItems.Remove(((int)EnumData.EnumOperationAccess.编辑).ToString()); isAccessChanged = true; if (apaItems.Count > 0) { userMenuInfo.OperationAccess = string.Join(",", apaItems.ToArray()).Trim(','); } else { userMenuInfo.OperationAccess = ""; } } } #endregion if (isAccessChanged) { if (isInsert) { userMenuBll.Insert(userMenuInfo); } else { userMenuBll.Update(userMenuInfo); } } } if (isChanged) { menuBll.Update(menuModel); } } return(ResResult.Response(true, "", "")); } catch (Exception ex) { return(ResResult.Response(false, "异常:" + ex.Message + "", "")); } }
public int Update(UserMenuInfo model) { return(dal.Update(model)); }
public int Insert(UserMenuInfo model) { return(dal.Insert(model)); }