Initial project import
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
using MiaoJiZhang.Infrastructure.Persistence;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace MiaoJiZhang.Api.Services;
|
||||
|
||||
public class LedgerResolver(AppDbContext db)
|
||||
{
|
||||
public async Task<long?> ResolveAsync(
|
||||
long userId,
|
||||
long? requestedLedgerId,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
if (requestedLedgerId.HasValue)
|
||||
{
|
||||
return await db.Ledgers
|
||||
.Where(l => l.Id == requestedLedgerId.Value && l.OwnerId == userId)
|
||||
.Select(l => (long?)l.Id)
|
||||
.FirstOrDefaultAsync(ct);
|
||||
}
|
||||
|
||||
return await db.Ledgers
|
||||
.Where(l => l.OwnerId == userId && l.IsDefault)
|
||||
.Select(l => (long?)l.Id)
|
||||
.FirstOrDefaultAsync(ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user