public static ApplicationUserExtended ToCoreModel(this ApplicationUser applicationUser, AccountEntity dbEntity, IPermissionScopeService scopeService) { var retVal = new ApplicationUserExtended(); retVal.InjectFrom(applicationUser); retVal.InjectFrom(dbEntity); retVal.UserState = EnumUtility.SafeParse(dbEntity.AccountState, AccountState.Approved); retVal.Roles = dbEntity.RoleAssignments.Select(x => x.Role.ToCoreModel(scopeService)).ToArray(); retVal.Permissions = retVal.Roles.SelectMany(x => x.Permissions).SelectMany(x => x.GetPermissionWithScopeCombinationNames()).Distinct().ToArray(); retVal.ApiAccounts = dbEntity.ApiAccounts.Select(x => x.ToCoreModel()).ToArray(); return(retVal); }
private ApplicationUserExtended GetUserExtended(ApplicationUser applicationUser, UserDetails detailsLevel) { ApplicationUserExtended result = null; if (applicationUser != null) { result = new ApplicationUserExtended(); result.InjectFrom(applicationUser); using (var repository = _platformRepository()) { var user = repository.GetAccountByName(applicationUser.UserName, detailsLevel); if (user != null) { result.InjectFrom(user); result.UserState = (UserState)user.AccountState; result.UserType = (UserType)user.RegisterType; if (detailsLevel == UserDetails.Full || detailsLevel == UserDetails.Export) { var roles = user.RoleAssignments.Select(x => x.Role).ToArray(); result.Roles = roles.Select(r => r.ToCoreModel()).ToArray(); var permissionIds = roles .SelectMany(x => x.RolePermissions) .Select(x => x.PermissionId) .Distinct() .ToArray(); result.Permissions = permissionIds; result.ApiAccounts = user.ApiAccounts.Select(x => x.ToCoreModel()).ToArray(); } } } if (detailsLevel != UserDetails.Export) { result.PasswordHash = null; result.SecurityStamp = null; } } return(result); }
private ApplicationUserExtended GetUserExtended(ApplicationUser applicationUser, UserDetails detailsLevel) { ApplicationUserExtended result = null; if (applicationUser != null) { result = new ApplicationUserExtended(); result.InjectFrom(applicationUser); using (var repository = _platformRepository()) { var user = repository.GetAccountByName(applicationUser.UserName, detailsLevel); if (user != null) { result.InjectFrom(user); result.UserState = (UserState)user.AccountState; result.UserType = (UserType)user.RegisterType; if (detailsLevel == UserDetails.Full) { var roles = user.RoleAssignments.Select(x => x.Role).ToArray(); result.Roles = roles.Select(r => r.ToCoreModel(false)).ToArray(); var permissionIds = roles .SelectMany(x => x.RolePermissions) .Select(x => x.PermissionId) .Distinct() .ToArray(); result.Permissions = permissionIds; result.ApiAcounts = user.ApiAccounts.Select(x => x.ToWebModel()).ToList(); } } } } return result; }