forked from siteserver/cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserGroupManager.cs
More file actions
70 lines (58 loc) · 2.04 KB
/
UserGroupManager.cs
File metadata and controls
70 lines (58 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System.Collections.Generic;
using System.Linq;
using SiteServer.CMS.Core;
using SiteServer.CMS.DataCache.Core;
using SiteServer.CMS.Model;
namespace SiteServer.CMS.DataCache
{
public static class UserGroupManager
{
private static class UserGroupManagerCache
{
private static readonly object LockObject = new object();
private static readonly string CacheKey = DataCacheManager.GetCacheKey(nameof(UserGroupManager));
public static void Clear()
{
DataCacheManager.Remove(CacheKey);
}
public static List<UserGroupInfo> GetAllUserGroups()
{
var retval = DataCacheManager.Get<List<UserGroupInfo>>(CacheKey);
if (retval != null) return retval;
lock (LockObject)
{
retval = DataCacheManager.Get<List<UserGroupInfo>>(CacheKey);
if (retval == null)
{
retval = DataProvider.UserGroupDao.GetUserGroupInfoList() ?? new List<UserGroupInfo>();
DataCacheManager.Insert(CacheKey, retval);
}
}
return retval;
}
}
public static void ClearCache()
{
UserGroupManagerCache.Clear();
}
public static bool IsExists(string groupName)
{
var list = UserGroupManagerCache.GetAllUserGroups();
return list.Any(group => group.GroupName == groupName);
}
public static UserGroupInfo GetUserGroupInfo(int groupId)
{
var list = UserGroupManagerCache.GetAllUserGroups();
return list.FirstOrDefault(group => group.Id == groupId) ?? list[0];
}
public static UserGroupInfo GetUserGroupInfo(string groupName)
{
var list = UserGroupManagerCache.GetAllUserGroups();
return list.FirstOrDefault(group => group.GroupName == groupName) ?? list[0];
}
public static List<UserGroupInfo> GetUserGroupInfoList()
{
return UserGroupManagerCache.GetAllUserGroups();
}
}
}