diff options
author | crupest <crupest@outlook.com> | 2020-01-21 01:11:17 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-01-21 01:11:17 +0800 |
commit | 4aadb05cd5718c7d16bf432c96e23ae4e7db4783 (patch) | |
tree | a45506852659b9d8e2bfe0b9e58a496060f7cd9b /Timeline/Models/UserConvert.cs | |
parent | e6069a6980ec6d2505e19026d4c84a9588f153dc (diff) | |
download | timeline-4aadb05cd5718c7d16bf432c96e23ae4e7db4783.tar.gz timeline-4aadb05cd5718c7d16bf432c96e23ae4e7db4783.tar.bz2 timeline-4aadb05cd5718c7d16bf432c96e23ae4e7db4783.zip |
...
Diffstat (limited to 'Timeline/Models/UserConvert.cs')
-rw-r--r-- | Timeline/Models/UserConvert.cs | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/Timeline/Models/UserConvert.cs b/Timeline/Models/UserConvert.cs deleted file mode 100644 index 5b132421..00000000 --- a/Timeline/Models/UserConvert.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System;
-using System.Collections.Generic;
-using System.Linq;
-using Timeline.Entities;
-using Timeline.Services;
-
-namespace Timeline.Models
-{
- public static class UserConvert
- {
- public static UserInfo CreateUserInfo(User user)
- {
- if (user == null)
- throw new ArgumentNullException(nameof(user));
- return new UserInfo(user.Name, UserRoleConvert.ToBool(user.RoleString));
- }
-
- internal static UserCache CreateUserCache(User user)
- {
- if (user == null)
- throw new ArgumentNullException(nameof(user));
- return new UserCache
- {
- Username = user.Name,
- Administrator = UserRoleConvert.ToBool(user.RoleString),
- Version = user.Version
- };
- }
- }
-
- [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);
- }
- }
-}
|