diff options
author | 杨宇千 <crupest@outlook.com> | 2019-08-08 16:54:03 +0800 |
---|---|---|
committer | 杨宇千 <crupest@outlook.com> | 2019-08-08 16:54:03 +0800 |
commit | ed85aa28b49789aa413a7e10637368c812411640 (patch) | |
tree | da11e395a3fd1340187fb785fc17e570171b942b /Timeline/Models/UserUtility.cs | |
parent | 57151c879376374425adb04fb68dad2cf7930df8 (diff) | |
parent | 29bd71cd93b03248254f341aff9252374abc74ec (diff) | |
download | timeline-ed85aa28b49789aa413a7e10637368c812411640.tar.gz timeline-ed85aa28b49789aa413a7e10637368c812411640.tar.bz2 timeline-ed85aa28b49789aa413a7e10637368c812411640.zip |
Merge branch 'master' into null-request-field
Diffstat (limited to 'Timeline/Models/UserUtility.cs')
-rw-r--r-- | Timeline/Models/UserUtility.cs | 120 |
1 files changed, 60 insertions, 60 deletions
diff --git a/Timeline/Models/UserUtility.cs b/Timeline/Models/UserUtility.cs index 711e321a..405987b5 100644 --- a/Timeline/Models/UserUtility.cs +++ b/Timeline/Models/UserUtility.cs @@ -1,60 +1,60 @@ -using System; -using System.Linq; -using Timeline.Entities; -using Timeline.Services; - -namespace Timeline.Models -{ - public static class UserUtility - { - public const string UserRole = UserRoles.User; - public const string AdminRole = UserRoles.Admin; - - public static string[] UserRoleArray { get; } = new string[] { UserRole }; - public static string[] AdminRoleArray { get; } = new string[] { UserRole, AdminRole }; - - public static string[] IsAdminToRoleArray(bool isAdmin) - { - return isAdmin ? AdminRoleArray : UserRoleArray; - } - - public static bool RoleArrayToIsAdmin(string[] roles) - { - return roles.Contains(AdminRole); - } - - public static string[] RoleStringToRoleArray(string roleString) - { - return roleString.Split(',').ToArray(); - } - - public static string RoleArrayToRoleString(string[] roles) - { - return string.Join(',', roles); - } - - public static string IsAdminToRoleString(bool isAdmin) - { - return RoleArrayToRoleString(IsAdminToRoleArray(isAdmin)); - } - - public static bool RoleStringToIsAdmin(string roleString) - { - return RoleArrayToIsAdmin(RoleStringToRoleArray(roleString)); - } - - public static UserInfo CreateUserInfo(User user) - { - if (user == null) - throw new ArgumentNullException(nameof(user)); - return new UserInfo(user.Name, RoleStringToIsAdmin(user.RoleString)); - } - - internal static UserCache CreateUserCache(User user) - { - if (user == null) - throw new ArgumentNullException(nameof(user)); - return new UserCache { Username = user.Name, Administrator = RoleStringToIsAdmin(user.RoleString), Version = user.Version }; - } - } -} +using System;
+using System.Linq;
+using Timeline.Entities;
+using Timeline.Services;
+
+namespace Timeline.Models
+{
+ public static class UserUtility
+ {
+ public const string UserRole = UserRoles.User;
+ public const string AdminRole = UserRoles.Admin;
+
+ public static string[] UserRoleArray { get; } = new string[] { UserRole };
+ public static string[] AdminRoleArray { get; } = new string[] { UserRole, AdminRole };
+
+ public static string[] IsAdminToRoleArray(bool isAdmin)
+ {
+ return isAdmin ? AdminRoleArray : UserRoleArray;
+ }
+
+ public static bool RoleArrayToIsAdmin(string[] roles)
+ {
+ return roles.Contains(AdminRole);
+ }
+
+ public static string[] RoleStringToRoleArray(string roleString)
+ {
+ return roleString.Split(',').ToArray();
+ }
+
+ public static string RoleArrayToRoleString(string[] roles)
+ {
+ return string.Join(',', roles);
+ }
+
+ public static string IsAdminToRoleString(bool isAdmin)
+ {
+ return RoleArrayToRoleString(IsAdminToRoleArray(isAdmin));
+ }
+
+ public static bool RoleStringToIsAdmin(string roleString)
+ {
+ return RoleArrayToIsAdmin(RoleStringToRoleArray(roleString));
+ }
+
+ public static UserInfo CreateUserInfo(User user)
+ {
+ if (user == null)
+ throw new ArgumentNullException(nameof(user));
+ return new UserInfo(user.Name, RoleStringToIsAdmin(user.RoleString));
+ }
+
+ internal static UserCache CreateUserCache(User user)
+ {
+ if (user == null)
+ throw new ArgumentNullException(nameof(user));
+ return new UserCache { Username = user.Name, Administrator = RoleStringToIsAdmin(user.RoleString), Version = user.Version };
+ }
+ }
+}
|