diff --git a/src/NadekoBot/Db/Extensions/GuildConfigExtensions.cs b/src/NadekoBot/Db/Extensions/GuildConfigExtensions.cs index 61d4b2bea..628a39cc7 100644 --- a/src/NadekoBot/Db/Extensions/GuildConfigExtensions.cs +++ b/src/NadekoBot/Db/Extensions/GuildConfigExtensions.cs @@ -73,6 +73,7 @@ public static class GuildConfigExtensions { GuildConfig config; + // todo linq2db if (includes is null) config = ctx.GuildConfigs.IncludeEverything().FirstOrDefault(c => c.GuildId == guildId); else @@ -100,6 +101,26 @@ public static class GuildConfigExtensions } return config; + + // ctx.GuildConfigs + // .ToLinqToDBTable() + // .InsertOrUpdate(() => new() + // { + // GuildId = guildId, + // Permissions = Permissionv2.GetDefaultPermlist, + // WarningsInitialized = true, + // WarnPunishments = DefaultWarnPunishments + // }, + // _ => new(), + // () => new() + // { + // GuildId = guildId + // }); + // + // if(includes is null) + // return ctx.GuildConfigs + // .ToLinqToDBTable() + // .First(x => x.GuildId == guildId); } public static LogSetting LogSettingsFor(this NadekoContext ctx, ulong guildId) diff --git a/src/NadekoBot/Services/Currency/CurrencyServiceExtensions.cs b/src/NadekoBot/Services/Currency/CurrencyServiceExtensions.cs index f0cf631a1..a5972ddbd 100644 --- a/src/NadekoBot/Services/Currency/CurrencyServiceExtensions.cs +++ b/src/NadekoBot/Services/Currency/CurrencyServiceExtensions.cs @@ -10,6 +10,7 @@ public static class CurrencyServiceExtensions return await wallet.GetBalance(); } + // todo transfer should be a transaction public static async Task TransferAsync( this ICurrencyService cs, ulong fromId, diff --git a/src/NadekoBot/Services/Currency/DefaultWallet.cs b/src/NadekoBot/Services/Currency/DefaultWallet.cs index 3e7f08ddd..581ff344a 100644 --- a/src/NadekoBot/Services/Currency/DefaultWallet.cs +++ b/src/NadekoBot/Services/Currency/DefaultWallet.cs @@ -43,17 +43,18 @@ public class DefaultWallet : IWallet if (changed == 0) return false; - await using var ctx2 = ctx.CreateLinqToDbContext(); - await ctx2 - .InsertAsync(new CurrencyTransaction() - { - Amount = -amount, - Note = txData.Note, - UserId = UserId, - Type = txData.Type, - Extra = txData.Extra, - OtherId = txData.OtherId - }); + await ctx + .GetTable() + .InsertAsync(() => new() + { + Amount = -amount, + Note = txData.Note, + UserId = UserId, + Type = txData.Type, + Extra = txData.Extra, + OtherId = txData.OtherId, + DateAdded = DateTime.UtcNow + }); return true; } @@ -88,17 +89,16 @@ public class DefaultWallet : IWallet await tran.CommitAsync(); } - var ct = new CurrencyTransaction() - { - Amount = amount, - UserId = UserId, - Note = txData.Note, - Type = txData.Type, - Extra = txData.Extra, - OtherId = txData.OtherId - }; - - await using var ctx2 = ctx.CreateLinqToDbContext(); - await ctx2.InsertAsync(ct); + await ctx.GetTable() + .InsertAsync(() => new() + { + Amount = amount, + UserId = UserId, + Note = txData.Note, + Type = txData.Type, + Extra = txData.Extra, + OtherId = txData.OtherId, + DateAdded = DateTime.UtcNow + }); } } \ No newline at end of file