public virtual async Task <TDto> GetMappedItemOrThrow <TDto>(GetByIdSpec <TEntity> spec, IMapper mapper) { var item = await GetItemOrThrow(spec) .ConfigureAwait(false); return(mapper.Map <TDto>(item)); }
public virtual async Task <TEntity> GetItem(int itemId) { var spec = new GetByIdSpec <TEntity>() { Id = itemId }; return(await GetItem(spec) .ConfigureAwait(false)); }
public virtual async Task <TEntity> GetItemOrThrow(GetByIdSpec <TEntity> spec) { var item = await GetItem(spec).ConfigureAwait(false); if (item == null) { throw new Exception($"Сущность не найдена"); } return(item); }
public virtual async Task <TEntity> GetItem(GetByIdSpec <TEntity> spec) { if (spec.Id <= 0) { throw new ArgumentOutOfRangeException(nameof(spec.Id)); } return(await _repository .GetItemById(spec) .ConfigureAwait(false)); }
public async Task <TEntity> GetItemById <TEntity>(GetByIdSpec <TEntity> spec) where TEntity : class, IDbEntity => await _db.Set <TEntity>() .ApplyJoin(spec.Join) .ApplyTracking(spec.AsNoTracking) .FirstOrDefaultAsync(x => x.Id == spec.Id);
/// <summary> /// получить сущность по Id /// </summary> public TEntity GetItemById <TEntity>(GetByIdSpec <TEntity> spec) where TEntity : class, IDbEntity => GetQueryable <TEntity>() .ApplyJoin(spec.Join) .FirstOrDefault(x => x.Id == spec.Id);