elliebot/src/EllieBot/Db/Extensions/CurrencyTransactionExtensions.cs

29 lines
845 B
C#
Raw Normal View History

2024-09-20 21:07:27 +12:00
#nullable disable
using LinqToDB.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using EllieBot.Db.Models;
namespace EllieBot.Db;
public static class CurrencyTransactionExtensions
{
2025-03-09 17:27:00 +13:00
public static async Task<IReadOnlyCollection<CurrencyTransaction>> GetPageFor(
2024-09-20 21:07:27 +12:00
this DbSet<CurrencyTransaction> set,
ulong userId,
int page)
2025-03-09 17:27:00 +13:00
{
var items = await set.ToLinqToDBTable()
2024-09-20 21:07:27 +12:00
.Where(x => x.UserId == userId)
.OrderByDescending(x => x.DateAdded)
.Skip(15 * page)
.Take(15)
.ToListAsyncLinqToDB();
2025-03-09 17:27:00 +13:00
return items;
}
public static async Task<int> GetCountFor(this DbSet<CurrencyTransaction> set, ulong userId)
=> await set.ToLinqToDBTable()
.Where(x => x.UserId == userId)
.CountAsyncLinqToDB();
2024-09-20 21:07:27 +12:00
}