Beispiel #1
0
        public async Task <Player> GetOrCreatePlayer(ulong discordId, ulong guildId)
        {
            using var context = new TicTacToeContext(_options);

            var profile = await context.Players
                          .Where(x => x.GuildId == guildId).FirstOrDefaultAsync(x => x.UserId == discordId);

            if (profile != null)
            {
                return(profile);
            }

            profile = new Player
            {
                UserId   = discordId,
                GuildId  = guildId,
                isBanned = false,
                Wins     = 0,
                Losses   = 0,
                Abandons = 0
            };

            context.Add(profile);

            await context.SaveChangesAsync();

            return(profile);
        }
Beispiel #2
0
        public async Task CreateNewPlayerAsync(Player player)
        {
            using var context = new TicTacToeContext(_options);

            context.Add(player);

            await context.SaveChangesAsync();
        }
        public async Task <PlayfieldState> CreatePlayfieldStateAsync(CreatePlayfieldState createPlayfieldState)
        {
            var playfieldState = new PlayfieldState(createPlayfieldState.State);

            playfieldState.GenerateBaseOptions();

            context.PlayfieldStates.Add(playfieldState);
            await context.SaveChangesAsync().ConfigureAwait(false);

            return(playfieldState);
        }
Beispiel #4
0
        public async Task UpdatePlayer(Player player)
        {
            using var context = new TicTacToeContext(_options);

            //Player gotPlayer =  await context.Players.FirstOrDefaultAsync(x => x.Id == player.Id);

            //gotPlayer = player;

            context.Update(player);

            await context.SaveChangesAsync();
        }