Пример #1
0
        public async Task <TEntity> AddAsync(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException($"{nameof(AddAsync)} entity must not be null");
            }

            try
            {
                await context.Set <TEntity>().AddAsync(entity);

                await context.SaveChangesAsync();

                return(entity);
            }
            catch (Exception ex)
            {
                throw new Exception($"{nameof(entity)} could not be saved: {ex.Message}");
            }
        }
Пример #2
0
 public TEntity Add(TEntity entity)
 {
     Context.Set <TEntity>().Add(entity);
     Context.SaveChanges();
     return(entity);
 }
Пример #3
0
 public Repository(CommerceContext dbContext)
 {
     _dbContext = dbContext;
     _dbSet     = dbContext.Set <TEntity>();
 }