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 AssertExists(Guid entityId) { var means = await _repository.GetAsync(entityId); if (means is null) { throw new BaristaException("authentication_means_not_found", $"Could not find authentication means with ID '{entityId}'"); } }
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 <AuthenticationMeansDto> HandleAsync(GetAuthenticationMeans query) { return(_mapper.MapToWithNullPropagation <AuthenticationMeansDto>(await _repository.GetAsync(query.Id))); }