Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }