public async Task <IOperationResult> HandleAsync(IUpdateAuthenticationMeans command, ICorrelationContext context) { if (command is null) { throw new ArgumentNullException(nameof(command)); } var means = await _repository.GetAsync(command.Id); if (means is null) { throw new BaristaException("means_not_found", $"Authentication means with ID '{command.Id}' was not found"); } means.SetMethod(command.Type); means.SetLabel(command.Label); means.SetValidity(command.ValidSince, command.ValidUntil); await _repository.UpdateAsync(means); await _repository.SaveChanges(); await _busPublisher.Publish(new AuthenticationMeansUpdated(means.Id, means.Label, means.Method, means.ValidSince, means.ValidUntil)); return(OperationResult.Ok()); }
public async Task <IOperationResult> HandleAsync(IDeleteAuthenticationMeans command, ICorrelationContext context) { if (command is null) { throw new ArgumentNullException(nameof(command)); } if (!(await _repository.GetAsync(command.Id) is Domain.AuthenticationMeans means)) { throw new BaristaException("means_not_found", $"Authentication means with ID '{command.Id}' was not found"); } await _repository.DeleteAsync(means); await _repository.SaveChanges(); await _busPublisher.Publish(new AuthenticationMeansDeleted(command.Id)); return(OperationResult.Ok()); }
public async Task <IIdentifierResult> HandleAsync(ICreateAuthenticationMeans command, ICorrelationContext context) { if (command is null) { throw new ArgumentNullException(nameof(command)); } var means = new Domain.AuthenticationMeans(command.Id, command.Label, command.Method, command.Value, command.ValidSince, command.ValidUntil); await _repository.AddAsync(means); try { await _repository.SaveChanges(); } catch (EntityAlreadyExistsException) { throw new BaristaException("authentication_means_already_exists", $"An authentication means with the ID '{command.Id}' already exists."); } await _busPublisher.Publish(new AuthenticationMeansCreated(means.Id, means.Label, means.Method, means.ValidSince, means.ValidUntil)); return(new IdentifierResult(means.Id)); }