await usings and minor cleanup

This commit is contained in:
Kwoth
2021-12-20 03:02:02 +01:00
parent 1b2017024c
commit da2ee0c158
55 changed files with 176 additions and 174 deletions

View File

@@ -33,7 +33,7 @@ public class ShopService : IShopService, INService
if (newPrice <= 0)
throw new ArgumentOutOfRangeException(nameof(newPrice));
using var uow = _db.GetDbContext();
await using var uow = _db.GetDbContext();
var entries = GetEntriesInternal(uow, guildId);
if (index >= entries.Count)
@@ -51,7 +51,7 @@ public class ShopService : IShopService, INService
if (string.IsNullOrWhiteSpace(newName))
throw new ArgumentNullException(nameof(newName));
using var uow = _db.GetDbContext();
await using var uow = _db.GetDbContext();
var entries = GetEntriesInternal(uow, guildId);
if (index >= entries.Count)
@@ -69,7 +69,7 @@ public class ShopService : IShopService, INService
if (index2 < 0)
throw new ArgumentOutOfRangeException(nameof(index2));
using var uow = _db.GetDbContext();
await using var uow = _db.GetDbContext();
var entries = GetEntriesInternal(uow, guildId);
if (index1 >= entries.Count || index2 >= entries.Count || index1 == index2)
@@ -89,7 +89,7 @@ public class ShopService : IShopService, INService
if (toIndex < 0)
throw new ArgumentOutOfRangeException(nameof(toIndex));
using var uow = _db.GetDbContext();
await using var uow = _db.GetDbContext();
var entries = GetEntriesInternal(uow, guildId);
if (fromIndex >= entries.Count || toIndex >= entries.Count || fromIndex == toIndex)

View File

@@ -219,7 +219,7 @@ public class PlantPickService : INService
var pw = config.Generation.HasPassword ? GenerateCurrencyPassword().ToUpperInvariant() : null;
IUserMessage sent;
using (var stream = GetRandomCurrencyImage(pw, out var ext))
await using (var stream = GetRandomCurrencyImage(pw, out var ext))
{
sent = await channel.SendFileAsync(stream, $"currency_image.{ext}", toSend).ConfigureAwait(false);
}
@@ -259,7 +259,7 @@ public class PlantPickService : INService
{
long amount;
ulong[] ids;
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
// this method will sum all plants with that password,
// remove them, and get messageids of the removed plants
@@ -318,7 +318,7 @@ public class PlantPickService : INService
msgToSend += " " + GetText(gid, strs.pick_sn(prefix));
//get the image
using (var stream = GetRandomCurrencyImage(pass, out var ext))
await using (var stream = GetRandomCurrencyImage(pass, out var ext))
{
// send it
var msg = await ch.SendFileAsync(stream, $"img.{ext}", msgToSend).ConfigureAwait(false);
@@ -362,7 +362,7 @@ public class PlantPickService : INService
private async Task AddPlantToDatabase(ulong gid, ulong cid, ulong uid, ulong mid, long amount, string pass)
{
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
uow.PlantedCurrency.Add(new()
{

View File

@@ -39,8 +39,8 @@ public class WaifuService : INService
return false;
var settings = _gss.Data;
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
var waifu = uow.WaifuInfo.ByWaifuUserId(waifuId);
var ownerUser = uow.GetOrCreateUser(owner);
@@ -116,7 +116,7 @@ public class WaifuService : INService
public async Task<bool> TryReset(IUser user)
{
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
var price = GetResetPrice(user);
if (!await _cs.RemoveAsync(user.Id, "Waifu Reset", price, gamble: true))
@@ -161,7 +161,7 @@ public class WaifuService : INService
WaifuClaimResult result;
WaifuInfo w;
bool isAffinity;
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
w = uow.WaifuInfo.ByWaifuUserId(target.Id);
isAffinity = (w?.Affinity?.UserId == user.Id);
@@ -251,7 +251,7 @@ public class WaifuService : INService
DiscordUser oldAff = null;
var success = false;
TimeSpan? remaining = null;
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
var w = uow.WaifuInfo.ByWaifuUserId(user.Id);
var newAff = target is null ? null : uow.GetOrCreateUser(target);
@@ -323,7 +323,7 @@ public class WaifuService : INService
TimeSpan? remaining = null;
long amount = 0;
WaifuInfo w = null;
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
w = uow.WaifuInfo.ByWaifuUserId(targetId);
var now = DateTime.UtcNow;
@@ -375,7 +375,7 @@ public class WaifuService : INService
return false;
}
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
var w = uow.WaifuInfo.ByWaifuUserId(giftedWaifu.Id,
set => set.Include(x => x.Items)