public UserHeader CreateActiveUser(string id, string password, string phrase, Role role) { var email = id + "@arb.org.uk"; var salt = _passwordManager.GenerateSalt(); var hashedPassword = _passwordManager.HashPassword(password, salt); var enctyptedSecurePhrase = _passwordManager.EncryptSecurePhrase(phrase); var existingUser = _database.GetUserByEmail(email); if (existingUser == null) { var user = new UserData { Id = Guid.NewGuid(), Email = email, FirstName = "User", LastName = id, Role = role, UserState = UserState.Activated, HashedPassword = hashedPassword, PasswordSalt = salt, EncryptedSecurePhrase = enctyptedSecurePhrase, FirstSecurePhraseQuestionCharacterIndex = 0, SecondSecurePhraseQuestionCharacterIndex = 1 }; _database.CreateUser(user); return user; } else { existingUser.HashedPassword = hashedPassword; existingUser.PasswordSalt = salt; existingUser.EncryptedSecurePhrase = enctyptedSecurePhrase; existingUser.FirstSecurePhraseQuestionCharacterIndex = 0; existingUser.SecondSecurePhraseQuestionCharacterIndex = 1; existingUser.UserState = UserState.Activated; _database.UpdateUser(existingUser); return existingUser; } }
private static int GetMaxUsersAssignedToCase(Role role) { if (role == Role.Admin || role == Role.None || role == Role.System) return 0; if (role == Role.CaseWorker) return 1; if (role == Role.PanelMember) return 3; if (role == Role.Inquirer || role == Role.Solicitor || role == Role.ThirdPartyReviewer) return int.MaxValue; throw new ArgumentException("unknown user role"); }
public OverAssignmentException(int caseId, Role role, UserHeader[] alreadyAssigned) { CaseId = caseId; Role = role; AlreadyAssigned = alreadyAssigned; }
private void CheckOverassignment(int caseId, Role role) { var assignedUsers = _database.GetAssignedUsers(caseId); var assignedUsersInRole = assignedUsers.Where(item => item.Role == role).ToArray(); var count = assignedUsersInRole.Length; var maxCount = GetMaxUsersAssignedToCase(role); if (count >= maxCount) throw new OverAssignmentException(caseId, role, assignedUsersInRole); }