Beispiel #1
0
 public async Task AddAsync <TEntity>(TEntity entity)
     where TEntity : class
 {
     try
     {
         await _retryPolicy.ExecuteAsync(async() =>
         {
             await _ekartDbContext.Set <TEntity>().AddAsync(entity).ConfigureAwait(false);
             await _ekartDbContext.SaveChangesAsync().ConfigureAwait(false);
         }).ConfigureAwait(false);
     }
     catch (DbUpdateException dbEx)
     {
         _logger.LogError($"{nameof(Repository)}: Exception occurred {dbEx.Message}");
         throw;
     }
     catch (Exception ex)
     {
         _logger.LogError($"{nameof(Repository)}: Exception occurred {ex.Message}");
         throw;
     }
 }
Beispiel #2
0
        private static IQueryable <TEntity> GetQueryable <TEntity>(ekartContext _ekartDbContext,
                                                                   Expression <Func <TEntity, bool> > filter = null,
                                                                   Func <IQueryable <TEntity>, IOrderedQueryable <TEntity> > orderBy = null,
                                                                   string includeProperties = null,
                                                                   int?skip = null,
                                                                   int?take = null)
            where TEntity : class
        {
            includeProperties = includeProperties ?? string.Empty;
            IQueryable <TEntity> query = _ekartDbContext.Set <TEntity>();

            if (filter != null)
            {
                query = query.Where(filter);
            }

            foreach (var includeProperty in includeProperties.Split
                         (new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            {
                query = query.Include(includeProperty);
            }

            if (orderBy != null)
            {
                query = orderBy(query);
            }

            if (skip.HasValue)
            {
                query = query.Skip(skip.Value);
            }

            if (take.HasValue)
            {
                query = query.Take(take.Value);
            }

            return(query);
        }