public async Task <IEnumerable <User> > GetAll() { using (FootballStatisticsDbContext context = _context.CreateDbContext()) { var entities = await context.Users.ToListAsync(); return(entities); } }
public async Task <User> GetByUsername(string username) { using (FootballStatisticsDbContext context = _context.CreateDbContext()) { User entity = await context.Users .FirstOrDefaultAsync(e => e.Username == username); return(entity); } }
public async Task <User> GetByEmail(string email) { using (FootballStatisticsDbContext context = _context.CreateDbContext()) { User entity = await context.Users .FirstOrDefaultAsync(e => e.Email == email); return(entity); } }
public async Task <User> Get(int id) { using (FootballStatisticsDbContext context = _context.CreateDbContext()) { User entity = await context.Users .FirstOrDefaultAsync(e => e.Id == id); return(entity); } }
public async Task <T> Update(int id, T entity) { using (FootballStatisticsDbContext context = _context.CreateDbContext()) { entity.Id = id; context.Set <T>().Update(entity); await context.SaveChangesAsync(); return(entity); } }
public async Task <T> Create(T entity) { using (FootballStatisticsDbContext context = _context.CreateDbContext()) { EntityEntry <T> createdResult = await context.Set <T>().AddAsync(entity); await context.SaveChangesAsync(); return(createdResult.Entity); } }
public async Task <bool> Delete(int id) { using (FootballStatisticsDbContext context = _context.CreateDbContext()) { T entity = await context.Set <T>().FirstOrDefaultAsync((e) => e.Id == id); context.Set <T>().Remove(entity); await context.SaveChangesAsync(); return(true); } }