27 lines
752 B
C#
27 lines
752 B
C#
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);
|
|
}
|
|
}
|