UnitOfWork compltely removed. GetDbContext now returns a NadekoContext. Changed every access to contect via uow._context to uow

This commit is contained in:
Kwoth
2021-06-19 05:16:27 +02:00
parent 51a4499809
commit c127dcd1e3
81 changed files with 404 additions and 512 deletions

View File

@@ -58,7 +58,7 @@ namespace NadekoBot.Modules.Music
using (var uow = _db.GetDbContext())
{
playlists = uow._context.MusicPlaylists.GetPlaylistsOnPage(num);
playlists = uow.MusicPlaylists.GetPlaylistsOnPage(num);
}
var embed = new EmbedBuilder()
@@ -78,13 +78,13 @@ namespace NadekoBot.Modules.Music
{
using (var uow = _db.GetDbContext())
{
var pl = uow._context.MusicPlaylists.FirstOrDefault(x => x.Id == id);
var pl = uow.MusicPlaylists.FirstOrDefault(x => x.Id == id);
if (pl != null)
{
if (_creds.IsOwner(ctx.User) || pl.AuthorId == ctx.User.Id)
{
uow._context.MusicPlaylists.Remove(pl);
uow.MusicPlaylists.Remove(pl);
await uow.SaveChangesAsync();
success = true;
}
@@ -112,7 +112,7 @@ namespace NadekoBot.Modules.Music
MusicPlaylist mpl;
using (var uow = _db.GetDbContext())
{
mpl = uow._context.MusicPlaylists.GetWithSongs(id);
mpl = uow.MusicPlaylists.GetWithSongs(id);
}
await ctx.SendPaginatedConfirmAsync(page, (cur) =>
@@ -158,7 +158,7 @@ namespace NadekoBot.Modules.Music
AuthorId = ctx.User.Id,
Songs = songs.ToList(),
};
uow._context.MusicPlaylists.Add(playlist);
uow.MusicPlaylists.Add(playlist);
await uow.SaveChangesAsync();
}
@@ -210,7 +210,7 @@ namespace NadekoBot.Modules.Music
MusicPlaylist mpl;
using (var uow = _db.GetDbContext())
{
mpl = uow._context.MusicPlaylists.GetWithSongs(id);
mpl = uow.MusicPlaylists.GetWithSongs(id);
}
if (mpl == null)

View File

@@ -13,7 +13,6 @@ using NadekoBot.Core.Services.Database.Repositories.Impl;
using NadekoBot.Modules.Music;
using NadekoBot.Services;
using NadekoBot.Services.Database.Models;
using NadekoBot.Services.Database.Repositories.Impl;
using NadekoBot.Extensions;
using Serilog;
@@ -352,7 +351,7 @@ namespace NadekoBot.Modules.Music.Services
return settings;
using var uow = _db.GetDbContext();
var toReturn = _settings[guildId] = await uow._context.MusicPlayerSettings.ForGuildAsync(guildId);
var toReturn = _settings[guildId] = await uow.MusicPlayerSettings.ForGuildAsync(guildId);
await uow.SaveChangesAsync();
return toReturn;
@@ -364,7 +363,7 @@ namespace NadekoBot.Modules.Music.Services
TState state)
{
using var uow = _db.GetDbContext();
var ms = await uow._context.MusicPlayerSettings.ForGuildAsync(guildId);
var ms = await uow.MusicPlayerSettings.ForGuildAsync(guildId);
action(ms, state);
await uow.SaveChangesAsync();
_settings[guildId] = ms;
@@ -444,7 +443,7 @@ namespace NadekoBot.Modules.Music.Services
public async Task<QualityPreset> GetMusicQualityAsync(ulong guildId)
{
using var uow = _db.GetDbContext();
var settings = await uow._context.MusicPlayerSettings.ForGuildAsync(guildId);
var settings = await uow.MusicPlayerSettings.ForGuildAsync(guildId);
return settings.QualityPreset;
}

View File

@@ -82,7 +82,7 @@
// {
// using (var uow = _db.GetDbContext())
// {
// return uow._context.GuildConfigsForId(guildId, set => set).DefaultMusicVolume;
// return uow.GuildConfigsForId(guildId, set => set).DefaultMusicVolume;
// }
// });
// }
@@ -256,7 +256,7 @@
// bool val;
// using (var uow = _db.GetDbContext())
// {
// var gc = uow._context.GuildConfigsForId(id, set => set);
// var gc = uow.GuildConfigsForId(id, set => set);
// val = gc.AutoDcFromVc = !gc.AutoDcFromVc;
// uow.SaveChanges();
// }
@@ -278,7 +278,7 @@
// {
// using (var uow = _db.GetDbContext())
// {
// var ms = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.MusicSettings)).MusicSettings;
// var ms = uow.GuildConfigsForId(guildId, set => set.Include(x => x.MusicSettings)).MusicSettings;
// ms.MusicChannelId = cid;
// uow.SaveChanges();
// }
@@ -288,7 +288,7 @@
// {
// using (var uow = _db.GetDbContext())
// {
// var ms = uow._context.GuildConfigsForId(guildId, set => set.Include(x => x.MusicSettings)).MusicSettings;
// var ms = uow.GuildConfigsForId(guildId, set => set.Include(x => x.MusicSettings)).MusicSettings;
// ms.SongAutoDelete = val;
// uow.SaveChanges();
// }

View File

@@ -395,7 +395,7 @@
// }
// using (var uow = _db.GetDbContext())
// {
// uow._context.GuildConfigsForId(ctx.Guild.Id, set => set).DefaultMusicVolume = val / 100.0f;
// uow.GuildConfigsForId(ctx.Guild.Id, set => set).DefaultMusicVolume = val / 100.0f;
// uow.SaveChanges();
// }
// await ReplyConfirmLocalizedAsync("defvol_set", val).ConfigureAwait(false);