public Task <IList <ApplicationUser> > GetUsersInRoleAsync(string roleName, CancellationToken cToken) { string prefix = nameof(GetUsersInRoleAsync) + Constants.FNSUFFIX; IList <ApplicationUser> users = new List <ApplicationUser>(); try { // Get the roleID from the roleName ApplicationRole appRole; using (var rolesDAL = new AspNetRolesDAL(_connStr)) { appRole = rolesDAL.SelectByRoleName(roleName.ToUpper()); } if (appRole != null) { // Get the userIDs that have this roleID IEnumerable <string> userIDsWithRoleID; using (var userRolesDAL = new AspNetUserRolesDAL(_connStr)) { userIDsWithRoleID = userRolesDAL.SelectUsersInRole(appRole.RoleId); } if (userIDsWithRoleID.Any()) { // Get the users with these userIDs using (var usersDAL = new AspNetUsersDAL(_connStr)) { users = usersDAL.SelectByUserIDs(userIDsWithRoleID).ToList(); } } } } catch (Exception ex) { _logger.LogError(prefix + $"Exception:[{ex.ToString()}]"); } return(Task.FromResult(users)); }
public Task SetTwoFactorEnabledAsync(ApplicationUser user, bool enabled, CancellationToken cancellationToken) { string prefix = nameof(SetTwoFactorEnabledAsync) + Constants.FNSUFFIX; user.TwoFactorEnabled = enabled; try { using (var usersDAL = new AspNetUsersDAL(_connStr)) { usersDAL.Update(user); } } catch (Exception ex) { _logger.LogError(prefix + $"Exception:[{ex.ToString()}]"); } return(Task.CompletedTask); }
public Task SetPhoneNumberAsync(ApplicationUser user, string phoneNumber, CancellationToken cancellationToken) { string prefix = nameof(SetPhoneNumberAsync) + Constants.FNSUFFIX; user.PhoneNumber = phoneNumber; try { using (var usersDAL = new AspNetUsersDAL(_connStr)) { usersDAL.Update(user); } } catch (Exception ex) { _logger.LogError(prefix + $"Exception:[{ex.ToString()}]"); } return(Task.CompletedTask); }
public Task <IdentityResult> UpdateAsync(ApplicationUser user, CancellationToken cancellationToken) { try { using (var usersDAL = new AspNetUsersDAL(_connStr)) { usersDAL.Update(user); } } catch (Exception ex) { List <IdentityError> idErrors = new List <IdentityError>(); IdentityError idError = new IdentityError { Description = ex.Message }; idErrors.Add(idError); return(Task.FromResult(IdentityResult.Failed(idErrors.ToArray()))); } return(Task.FromResult(IdentityResult.Success)); }
public Task <ApplicationUser> FindByEmailAsync(string normalizedEmail, CancellationToken cancellationToken) { string prefix = nameof(FindByEmailAsync) + Constants.FNSUFFIX; ApplicationUser appUser = null; if (!string.IsNullOrWhiteSpace(normalizedEmail)) { try { using (var usersDAL = new AspNetUsersDAL(_connStr)) { appUser = usersDAL.SelectByEmail(normalizedEmail); } } catch (Exception ex) { _logger.LogError(prefix + $"Exception:[{ex.ToString()}]"); } } return(Task.FromResult(appUser)); }