public Credential AddCredential(CredentialGroup group, Credential credential) { if (group == null) { throw new InvalidOperationException("Es muss eine Gruppe zugeordnet werden."); } else if (String.IsNullOrWhiteSpace(credential.Name)) { throw new InvalidOperationException("Der Name darf nicht leer sein."); } else if (_currentData.First(g => g == group).Credentials.Any(c => c.Name == credential.Name)) { throw new InvalidOperationException("Ein Eintrag mit diesem Namen existiert bereits."); } int id = Convert.ToInt32(_currentData.SelectMany(g => g?.Credentials)?.Max(c => c?.ID)) + 1; credential.ID = id; ICommand command = new AddCredentialCommand() { Group = group, CredentialToCreate = credential }; credential = (Credential)ExecuteCommand(command); return(credential); }
public async Task HandleAsync(AddCredentialCommand message, CancellationToken token = default(CancellationToken)) { var user = await this.GetUserAsync(message.UserId, token); user.AddCredential(message.CredentialTypeId, message.Identifier, message.Secret); await _users.SaveChangesAsync(token); }
public Credential DuplicateCredential(Credential credential) { if (credential == null) { throw new InvalidOperationException("Keine Credentials ausgewählt."); } Credential duplicate = (Credential)credential.Clone(); RenameCopy(duplicate); ICommand command = new AddCredentialCommand() { CredentialToCreate = duplicate, Group = duplicate.Group }; ExecuteCommand(command); return(duplicate); }