예제 #1
0
        public virtual async Task <TDto> GetMappedItemOrThrow <TDto>(GetByIdSpec <TEntity> spec, IMapper mapper)
        {
            var item = await GetItemOrThrow(spec)
                       .ConfigureAwait(false);

            return(mapper.Map <TDto>(item));
        }
예제 #2
0
        public virtual async Task <TEntity> GetItem(int itemId)
        {
            var spec = new GetByIdSpec <TEntity>()
            {
                Id = itemId
            };

            return(await GetItem(spec)
                   .ConfigureAwait(false));
        }
예제 #3
0
        public virtual async Task <TEntity> GetItemOrThrow(GetByIdSpec <TEntity> spec)
        {
            var item = await GetItem(spec).ConfigureAwait(false);

            if (item == null)
            {
                throw new Exception($"Сущность не найдена");
            }

            return(item);
        }
예제 #4
0
        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));
        }
예제 #5
0
 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);
예제 #6
0
 /// <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);