public async Task <List <Player> > GetAllAsync() { using (var db = new FootballBotDbContext(_options)) { return(await db.Players.ToListAsync()); } }
public async Task <List <Player> > GetReadyToPlayAsync() { using (var db = new FootballBotDbContext(_options)) { return((await db.Players.ToListAsync()).Where(p => p.IsGoingToPlay == true).ToList()); } }
public async Task <List <Player> > GetRecievedMessageAsync() { using (var db = new FootballBotDbContext(_options)) { return((await db.Players.ToListAsync()).Where(p => p.ApprovedPlayersMessageId != 0).ToList()); } }
public PlayerRepository(DbContextOptions <FootballBotDbContext> options) { _options = options; using (var db = new FootballBotDbContext(_options)) { db.Database.EnsureCreated(); } }
public async Task <Player> GetAsync(string name) { using (var db = new FootballBotDbContext(_options)) { var player = await db.Players.FirstOrDefaultAsync(p => p.Name.Equals(name, System.StringComparison.InvariantCultureIgnoreCase)); return(player ?? throw new UserNotFoundException()); } }
public async Task <Player> GetAsync(int id) { using (var db = new FootballBotDbContext(_options)) { var player = await db.Players.FindAsync(id); return(player ?? throw new UserNotFoundException()); } }
public async Task RemoveAsync(int id) { var player = await GetAsync(id); using (var db = new FootballBotDbContext(_options)) { db.Players.Remove(player); await db.SaveChangesAsync(); } }
public async Task UpdateAsync(Player player) { if (player == null || player.Id == default(int)) { return; } using (var db = new FootballBotDbContext(_options)) { db.Entry(player).State = EntityState.Modified; await db.SaveChangesAsync(); } }
public async Task AddAsync(Player player) { if (player == null) { return; } using (var db = new FootballBotDbContext(_options)) { db.Players.Add(player); await db.SaveChangesAsync(); } }
public async Task UpdateMultipleAsync(IEnumerable <Player> players) { if (!players.Any()) { return; } using (var db = new FootballBotDbContext(_options)) { foreach (var player in players) { db.Entry(player).State = EntityState.Modified; } await db.SaveChangesAsync(); } }