Exemple #1
0
        public async Task <T> GetByID(int id)
        {
            using (EsportMgmtDatabaseContext context = _context.CreateDbContext())
            {
                T entity = await context.Set <T>().FirstOrDefaultAsync(x => x.ID == id);

                return(entity);
            }
        }
Exemple #2
0
        public async Task <IEnumerable <T> > GetAll()
        {
            using (EsportMgmtDatabaseContext context = _context.CreateDbContext())
            {
                IEnumerable <T> entities = await context.Set <T>().ToListAsync();

                return(entities);
            }
        }
Exemple #3
0
        public async Task <T> Update(int id, T entity)
        {
            using (EsportMgmtDatabaseContext context = _context.CreateDbContext())
            {
                entity.ID = id;
                context.Set <T>().Update(entity);
                await context.SaveChangesAsync();

                return(entity);
            }
        }
Exemple #4
0
        public async Task <T> Create(T entity)
        {
            using (EsportMgmtDatabaseContext context = _context.CreateDbContext())
            {
                var createdEntity = await context.Set <T>().AddAsync(entity);

                await context.SaveChangesAsync();

                return(createdEntity.Entity);
            }
        }
Exemple #5
0
        public async Task <bool> Delete(T entityToDelete)
        {
            using (EsportMgmtDatabaseContext context = _context.CreateDbContext())
            {
                T entity = await context.Set <T>().FirstOrDefaultAsync(x => x == entityToDelete);

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

                return(true);
            }
        }