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(); } }
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(); } }
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(); }
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(); }
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; }
public ReplayListModel(ILogger <ReplayListModel> logger, DosDbContext context) { _logger = logger; this.context = context; }
public Replay(DosDbContext context) { this.context = context; }
private static async Task <GuildConfig> GetGuildConfigAsync(DosDbContext context, ulong serverId) { return(await context.GuildConfig.FirstOrDefaultAsync(c => c.GuildId == serverId)); }
private static async Task <GuildConfig> GetGuildConfigAsync(ulong serverId) { await using var context = new DosDbContext(); return(await GetGuildConfigAsync(context, serverId)); }