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

@@ -46,7 +46,7 @@ DELETE FROM Clubs;";
int res;
using (var uow = _db.GetDbContext())
{
res = await uow._context.Database.ExecuteSqlRawAsync(sql);
res = await uow.Database.ExecuteSqlRawAsync(sql);
}
return res;
}
@@ -67,7 +67,7 @@ DELETE FROM Clubs;";
using (var uow = _db.GetDbContext())
{
var conn = uow._context.Database.GetDbConnection();
var conn = uow.Database.GetDbConnection();
using (var cmd = conn.CreateCommand())
{
cmd.CommandText = sql;
@@ -97,31 +97,31 @@ DELETE FROM Clubs;";
using var uow = _db.GetDbContext();
// get waifu info
var wi = await uow._context.Set<WaifuInfo>()
var wi = await uow.Set<WaifuInfo>()
.FirstOrDefaultAsyncEF(x => x.Waifu.UserId == userId);
// if it exists, delete waifu related things
if (!(wi is null))
{
// remove updates which have new or old as this waifu
await uow._context
await uow
.WaifuUpdates
.DeleteAsync(wu => wu.New.UserId == userId || wu.Old.UserId == userId);
// delete all items this waifu owns
await uow._context
await uow
.Set<WaifuItem>()
.DeleteAsync(x => x.WaifuInfoId == wi.Id);
// all waifus this waifu claims are released
await uow._context
await uow
.Set<WaifuInfo>()
.AsQueryable()
.Where(x => x.Claimer.UserId == userId)
.UpdateAsync(x => new WaifuInfo() {ClaimerId = null});
// all affinities set to this waifu are reset
await uow._context
await uow
.Set<WaifuInfo>()
.AsQueryable()
.Where(x => x.Affinity.UserId == userId)
@@ -129,16 +129,16 @@ DELETE FROM Clubs;";
}
// delete guild xp
await uow._context
await uow
.UserXpStats
.DeleteAsync(x => x.UserId == userId);
// delete currency transactions
await uow._context.Set<CurrencyTransaction>()
await uow.Set<CurrencyTransaction>()
.DeleteAsync(x => x.UserId == userId);
// delete user, currency, and clubs go away with it
await uow._context.DiscordUser
await uow.DiscordUser
.DeleteAsync(u => u.UserId == userId);
}
}