public async Task <bool> Delete(int id)
        {
            using (TraderDbContext context = _context.CreateDbContext())
            {
                T entity = await context.Set <T>().FirstOrDefaultAsync(e => e.id == id);

                context.Set <T>().Remove(entity);
                await context.SaveChangesAsync();

                return(true);
            }
        }
Exemplo n.º 2
0
        public async Task <IEnumerable <T> > GetAll()
        {
            using (TraderDbContext context = _context.CreateDbContext())
            {
                IEnumerable <T> entity = await context.Set <T>().ToListAsync();

                return(entity);
            }
        }
Exemplo n.º 3
0
        public async Task <T> Get(int Id)
        {
            using (TraderDbContext context = _context.CreateDbContext())
            {
                T entity = await context.Set <T>().FirstOrDefaultAsync(e => e.id == Id);

                return(entity);
            }
        }
        public async Task <T> Update(int id, T entity)
        {
            using (TraderDbContext context = _context.CreateDbContext())
            {
                entity.id = id;
                context.Set <T>().Update(entity);
                await context.SaveChangesAsync();

                return(entity);
            }
        }
        public async Task <T> Create(T entity)
        {
            using (TraderDbContext context = _context.CreateDbContext())
            {
                EntityEntry <T> createEntity = await context.Set <T>().AddAsync(entity);

                await context.SaveChangesAsync();

                return(createEntity.Entity);
            }
        }
Exemplo n.º 6
0
 public GenericDataService(TraderDbContext traderDbContext)
 {
     _traderDbContext = traderDbContext;
     _dbSet           = _traderDbContext.Set <T>();
 }