Beispiel #1
0
        public Task AddToRoleAsync(ApplicationUser user, string roleName, CancellationToken cancellationToken)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user), "Parameter user is not set to an instance of an object.");
            }

            if (string.IsNullOrEmpty(roleName))
            {
                throw new ArgumentNullException(nameof(roleName), "Parameter roleName is not set to an instance of an object.");
            }

            ApplicationRole role           = Task.Run(() => _rolesTable.GetAllRoles(), cancellationToken).Result.SingleOrDefault(e => e.NormalizedName == roleName);
            ApplicationUser newAddedUserId = Task.Run(() => _usersTable.GetAllUsers(), cancellationToken).Result.SingleOrDefault(e => e.NormalizedEmail == user.NormalizedEmail);

            if (newAddedUserId != null)
            {
                user.Id = newAddedUserId.Id;
            }

            return(role != null
                ? _usersRolesTable.AddToRoleAsync(user, role.Id)
                : Task.FromResult <object>(null));
        }
 // ============================================
 // PUBLIC Users Methods
 // ============================================
 public static string[] AccountUsers(int id)
 {
     UsersTable table = new UsersTable();
     string[] users = table.GetAllUsers(id);
     table.Dispose();
     return(users);
 }