示例#1
0
 public async Task <List <Player> > GetAllAsync()
 {
     using (var db = new FootballBotDbContext(_options))
     {
         return(await db.Players.ToListAsync());
     }
 }
示例#2
0
 public async Task <List <Player> > GetReadyToPlayAsync()
 {
     using (var db = new FootballBotDbContext(_options))
     {
         return((await db.Players.ToListAsync()).Where(p => p.IsGoingToPlay == true).ToList());
     }
 }
示例#3
0
 public async Task <List <Player> > GetRecievedMessageAsync()
 {
     using (var db = new FootballBotDbContext(_options))
     {
         return((await db.Players.ToListAsync()).Where(p => p.ApprovedPlayersMessageId != 0).ToList());
     }
 }
示例#4
0
 public PlayerRepository(DbContextOptions <FootballBotDbContext> options)
 {
     _options = options;
     using (var db = new FootballBotDbContext(_options))
     {
         db.Database.EnsureCreated();
     }
 }
示例#5
0
        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());
            }
        }
示例#6
0
        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());
            }
        }
示例#7
0
        public async Task RemoveAsync(int id)
        {
            var player = await GetAsync(id);

            using (var db = new FootballBotDbContext(_options))
            {
                db.Players.Remove(player);
                await db.SaveChangesAsync();
            }
        }
示例#8
0
        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();
            }
        }
示例#9
0
        public async Task AddAsync(Player player)
        {
            if (player == null)
            {
                return;
            }

            using (var db = new FootballBotDbContext(_options))
            {
                db.Players.Add(player);
                await db.SaveChangesAsync();
            }
        }
示例#10
0
        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();
            }
        }