public bool CreateUserForApplicationRecord(UserProfilePart profilePart, ApplicationRecord appRecord) { UserProfilePartRecord profileRecord = _userprofileRepository.Get(profilePart.Id); if (profileRecord == null) { return(false); } var utcNow = _clock.UtcNow; var record = profileRecord.Applications.FirstOrDefault(x => x.ApplicationRecord.Name == appRecord.Name); if (record == null) { profileRecord.Applications.Add(new UserApplicationRecord { UserProfilePartRecord = profileRecord, ApplicationRecord = appRecord, RegistrationStart = utcNow }); TriggerSignal(); } if (profileRecord.Roles == null || profileRecord.Roles.Count == 0) { UserRoleRecord defaultrole = _applicationsService.GetDefaultRole(appRecord); profileRecord.Roles.Add(new UserUserRoleRecord { UserProfilePartRecord = profileRecord, UserRoleRecord = defaultrole }); } return(true); }