using Bootstrap.Security; using Longbow.Cache; using Longbow.Data; using System.Collections.Generic; namespace Bootstrap.DataAccess { /// /// 用户表相关操作类 /// public static class UserHelper { public const string RetrieveUsersDataKey = "UserHelper-RetrieveUsers"; public const string RetrieveUsersByRoleIdDataKey = "UserHelper-RetrieveUsersByRoleId"; public const string RetrieveUsersByGroupIdDataKey = "UserHelper-RetrieveUsersByGroupId"; public const string RetrieveNewUsersDataKey = "UserHelper-RetrieveNewUsers"; public const string RetrieveUsersByNameDataKey = "BootstrapUser-RetrieveUsersByName"; /// /// 查询所有用户 /// /// /// public static IEnumerable RetrieveUsers() => CacheManager.GetOrAdd(RetrieveUsersDataKey, key => DbAdapterManager.Create().RetrieveUsers()); /// /// /// /// /// /// public static bool Authenticate(string userName, string password) => DbAdapterManager.Create().Authenticate(userName, password); /// /// 查询所有的新注册用户 /// /// public static IEnumerable RetrieveNewUsers() => CacheManager.GetOrAdd(RetrieveNewUsersDataKey, key => DbAdapterManager.Create().RetrieveNewUsers()); /// /// 删除用户 /// /// public static bool DeleteUser(IEnumerable value) => DbAdapterManager.Create().DeleteUser(value); /// /// 保存新建 /// /// /// public static bool SaveUser(User p) => DbAdapterManager.Create().SaveUser(p); /// /// /// /// /// /// /// public static bool UpdateUser(int id, string password, string displayName) => DbAdapterManager.Create().UpdateUser(id, password, displayName); /// /// /// /// /// /// public static bool ApproveUser(int id, string approvedBy) => DbAdapterManager.Create().ApproveUser(id, approvedBy); /// /// /// /// /// /// /// public static bool ChangePassword(string userName, string password, string newPass) => DbAdapterManager.Create().ChangePassword(userName, password, newPass); /// /// /// /// /// /// /// public static bool RejectUser(int id, string rejectBy) => DbAdapterManager.Create().RejectUser(id, rejectBy); /// /// 通过roleId获取所有用户 /// /// /// public static IEnumerable RetrieveUsersByRoleId(int roleId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByRoleIdDataKey, roleId), k => DbAdapterManager.Create().RetrieveUsersByRoleId(roleId), RetrieveUsersByRoleIdDataKey); /// /// 通过角色ID保存当前授权用户(插入) /// /// 角色ID /// 用户ID数组 /// public static bool SaveUsersByRoleId(int id, IEnumerable userIds) => DbAdapterManager.Create().SaveUsersByRoleId(id, userIds); /// /// 通过groupId获取所有用户 /// /// /// public static IEnumerable RetrieveUsersByGroupId(int groupId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByGroupIdDataKey, groupId), k => DbAdapterManager.Create().RetrieveUsersByGroupId(groupId), RetrieveUsersByRoleIdDataKey); /// /// 通过部门ID保存当前授权用户(插入) /// /// GroupID /// 用户ID数组 /// public static bool SaveUsersByGroupId(int id, IEnumerable userIds) => DbAdapterManager.Create().SaveUsersByGroupId(id, userIds); /// 根据用户名修改用户头像 /// /// /// /// public static bool SaveUserIconByName(string userName, string iconName) => DbAdapterManager.Create().SaveUserIconByName(userName, iconName); /// /// /// /// /// /// public static bool SaveDisplayName(string userName, string displayName) => DbAdapterManager.Create().SaveDisplayName(userName, displayName); /// /// 根据用户名更改用户皮肤 /// /// /// /// public static bool SaveUserCssByName(string userName, string cssName) => DbAdapterManager.Create().SaveUserCssByName(userName, cssName); /// /// /// /// /// public static BootstrapUser RetrieveUserByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName), k => DbAdapterManager.Create().RetrieveUserByUserName(userName), RetrieveUsersByNameDataKey); } }