public TEntity Handle(GetEntityByIdQuery <TEntity> query) { var entity = _repository.GetAll().FirstOrDefault(x => x.Id == query.Id); if (query.ThrowNotFoundIfNull && entity == null) { throw new NotFoundException($"Entity {query.Id} not found."); } return(entity); }
public async Task <TEntity> HandleAsync(GetEntityByIdQuery <TEntity> query, CancellationToken cancellationToken = default) { var entity = await _repository.FirstOrDefaultAsync(_repository.GetAll().Where(x => x.Id == query.Id)); if (query.ThrowNotFoundIfNull && entity == null) { throw new NotFoundException($"Entity {query.Id} not found."); } return(entity); }