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

@@ -12,7 +12,6 @@ using System.Threading.Tasks;
using NadekoBot.Core.Services;
using NadekoBot.Core.Services.Database.Models;
using NadekoBot.Core.Services.Database.Repositories.Impl;
using NadekoBot.Services.Database.Repositories.Impl;
using NadekoBot.Db;
namespace NadekoBot.Modules.Utility
@@ -47,7 +46,7 @@ namespace NadekoBot.Modules.Utility
IEnumerable<Quote> quotes;
using (var uow = _db.GetDbContext())
{
quotes = uow._context.Quotes.GetGroup(ctx.Guild.Id, page, order);
quotes = uow.Quotes.GetGroup(ctx.Guild.Id, page, order);
}
if (quotes.Any())
@@ -70,7 +69,7 @@ namespace NadekoBot.Modules.Utility
Quote quote;
using (var uow = _db.GetDbContext())
{
quote = await uow._context.Quotes.GetRandomQuoteByKeywordAsync(ctx.Guild.Id, keyword);
quote = await uow.Quotes.GetRandomQuoteByKeywordAsync(ctx.Guild.Id, keyword);
//if (quote != null)
//{
// quote.UseCount += 1;
@@ -102,7 +101,7 @@ namespace NadekoBot.Modules.Utility
Quote quote;
using (var uow = _db.GetDbContext())
{
quote = uow._context.Quotes.GetById(id);
quote = uow.Quotes.GetById(id);
if (quote.GuildId != Context.Guild.Id)
quote = null;
}
@@ -141,7 +140,7 @@ namespace NadekoBot.Modules.Utility
Quote keywordquote;
using (var uow = _db.GetDbContext())
{
keywordquote = await uow._context.Quotes.SearchQuoteKeywordTextAsync(ctx.Guild.Id, keyword, text);
keywordquote = await uow.Quotes.SearchQuoteKeywordTextAsync(ctx.Guild.Id, keyword, text);
}
if (keywordquote == null)
@@ -166,7 +165,7 @@ namespace NadekoBot.Modules.Utility
using (var uow = _db.GetDbContext())
{
quote = uow._context.Quotes.GetById(id);
quote = uow.Quotes.GetById(id);
}
if (quote is null || quote.GuildId != ctx.Guild.Id)
@@ -203,7 +202,7 @@ namespace NadekoBot.Modules.Utility
Quote q;
using (var uow = _db.GetDbContext())
{
uow._context.Quotes.Add(q = new Quote
uow.Quotes.Add(q = new Quote
{
AuthorId = ctx.Message.Author.Id,
AuthorName = ctx.Message.Author.Username,
@@ -226,7 +225,7 @@ namespace NadekoBot.Modules.Utility
string response;
using (var uow = _db.GetDbContext())
{
var q = uow._context.Quotes.GetById(id);
var q = uow.Quotes.GetById(id);
if ((q?.GuildId != ctx.Guild.Id) || (!isAdmin && q.AuthorId != ctx.Message.Author.Id))
{
@@ -234,7 +233,7 @@ namespace NadekoBot.Modules.Utility
}
else
{
uow._context.Quotes.Remove(q);
uow.Quotes.Remove(q);
await uow.SaveChangesAsync();
success = true;
response = GetText("quote_deleted", id);
@@ -258,7 +257,7 @@ namespace NadekoBot.Modules.Utility
using (var uow = _db.GetDbContext())
{
uow._context.Quotes.RemoveAllByKeyword(ctx.Guild.Id, keyword.ToUpperInvariant());
uow.Quotes.RemoveAllByKeyword(ctx.Guild.Id, keyword.ToUpperInvariant());
await uow.SaveChangesAsync();
}