aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Services/UserRoleConvert.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-01-29 23:13:15 +0800
committercrupest <crupest@outlook.com>2020-01-29 23:13:15 +0800
commitabde51b167f17301c25e32ae247e7909c0dc9367 (patch)
treec9131a7b95fffd64bf2c26527d7f62fbdefa7e2c /Timeline/Services/UserRoleConvert.cs
parent81c261b59016e15d320ad963882afe4d9c7b5f7d (diff)
downloadtimeline-abde51b167f17301c25e32ae247e7909c0dc9367.tar.gz
timeline-abde51b167f17301c25e32ae247e7909c0dc9367.tar.bz2
timeline-abde51b167f17301c25e32ae247e7909c0dc9367.zip
...
Diffstat (limited to 'Timeline/Services/UserRoleConvert.cs')
-rw-r--r--Timeline/Services/UserRoleConvert.cs44
1 files changed, 44 insertions, 0 deletions
diff --git a/Timeline/Services/UserRoleConvert.cs b/Timeline/Services/UserRoleConvert.cs
new file mode 100644
index 00000000..4fa4a7b8
--- /dev/null
+++ b/Timeline/Services/UserRoleConvert.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Timeline.Entities;
+
+namespace Timeline.Services
+{
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "No need.")]
+ public static class UserRoleConvert
+ {
+ public const string UserRole = UserRoles.User;
+ public const string AdminRole = UserRoles.Admin;
+
+ public static string[] ToArray(bool administrator)
+ {
+ return administrator ? new string[] { UserRole, AdminRole } : new string[] { UserRole };
+ }
+
+ public static string[] ToArray(string s)
+ {
+ return s.Split(',').ToArray();
+ }
+
+ public static bool ToBool(IReadOnlyCollection<string> roles)
+ {
+ return roles.Contains(AdminRole);
+ }
+
+ public static string ToString(IReadOnlyCollection<string> roles)
+ {
+ return string.Join(',', roles);
+ }
+
+ public static string ToString(bool administrator)
+ {
+ return administrator ? UserRole + "," + AdminRole : UserRole;
+ }
+
+ public static bool ToBool(string s)
+ {
+ return s.Contains("admin", StringComparison.InvariantCulture);
+ }
+ }
+}