コード例 #1
0
        private async Task DeleteReplay()
        {
            await using var context = new DosDbContext();
            var replay = await context.Replay.FindAsync(replayId);

            if (replay != null)
            {
                context.Replay.Remove(replay);
                await context.SaveChangesAsync();
            }
        }
コード例 #2
0
        private async Task FinishSavingReplay()
        {
            await using var context = new DosDbContext();
            var replay = await context.Replay.FindAsync(replayId);

            if (replay != null)
            {
                replay.IsOngoing = false;
                await context.SaveChangesAsync();
            }
        }
コード例 #3
0
        public async Task UpdateGameConfigAsync(ulong serverId, BotGameConfig config)
        {
            await using var dbContext = new DosDbContext();
            var guildConfig = await GetGuildConfigAsync(dbContext, serverId);

            if (guildConfig == null)
            {
                guildConfig = new GuildConfig
                {
                    GuildId = serverId
                };
                await dbContext.AddAsync(guildConfig);
            }
            guildConfig.Config = config;
            await dbContext.SaveChangesAsync();
        }
コード例 #4
0
 protected override void AppendEvent(GameLogEvent gameLogEvent, GameSnapshot gameSnapshot)
 {
     base.AppendEvent(gameLogEvent, gameSnapshot);
     using var context = new DosDbContext();
     context.ReplayMove.Add(new ReplayMove
     {
         TargetPlayer = gameLogEvent.TargetPlayer,
         SourcePlayer = gameLogEvent.SourcePlayer,
         Cards        = gameLogEvent.Cards,
         EventType    = gameLogEvent.EventType,
         ReplayId     = replayId
     });
     context.ReplaySnapshot.Add(new ReplaySnapshot
     {
         CenterRow       = gameSnapshot.CenterRow,
         PlayerHands     = gameSnapshot.PlayerHands,
         ReplayId        = replayId,
         CurrentPlayerId = gameSnapshot.CurrentPlayerId,
     });
     context.SaveChanges();
 }
コード例 #5
0
        private void Init(DiscordDosGame discordGame)
        {
            var replay = new Replay
            {
                GameStartDate = DateTime.UtcNow,
                Players       =
                    discordGame.Players.Select(p => new ReplayPlayer {
                    OrderId = p.OrderId, PlayerName = p.Name
                })
                    .ToList(),
                IsOngoing    = true,
                ChannelTitle = discordGame.Info.Channel.Name,
                GuildTitle   = discordGame.Info.ServerName,
                IsPublic     = discordGame.Config.PublishReplays
            };

            using var context = new DosDbContext();
            context.Replay.Add(replay);
            context.SaveChanges();

            replayId = replay.ReplayId;
        }
コード例 #6
0
 public ReplayListModel(ILogger <ReplayListModel> logger, DosDbContext context)
 {
     _logger      = logger;
     this.context = context;
 }
コード例 #7
0
 public Replay(DosDbContext context)
 {
     this.context = context;
 }
コード例 #8
0
 private static async Task <GuildConfig> GetGuildConfigAsync(DosDbContext context, ulong serverId)
 {
     return(await context.GuildConfig.FirstOrDefaultAsync(c => c.GuildId == serverId));
 }
コード例 #9
0
 private static async Task <GuildConfig> GetGuildConfigAsync(ulong serverId)
 {
     await using var context = new DosDbContext();
     return(await GetGuildConfigAsync(context, serverId));
 }