using Microsoft.EntityFrameworkCore; using Fengling.RiskControl.Domain.Aggregates.LotteryActivities; using Fengling.RiskControl.Domain.Repositories; namespace Fengling.RiskControl.Infrastructure.Repositories; public class LotteryActivityRepository : ILotteryActivityRepository { private readonly RiskControlDbContext _context; public LotteryActivityRepository(RiskControlDbContext context) { _context = context; } public async Task GetByIdAsync(long id) { return await _context.LotteryActivities.FindAsync(id); } public async Task> GetByMemberIdAsync(long memberId) { return await _context.LotteryActivities .Where(l => l.MemberId == memberId) .OrderByDescending(l => l.CreatedAt) .ToListAsync(); } public async Task> GetRecentByMemberIdAsync(long memberId, int count) { return await _context.LotteryActivities .Where(l => l.MemberId == memberId) .OrderByDescending(l => l.CreatedAt) .Take(count) .ToListAsync(); } public async Task AddAsync(LotteryActivity activity) { await _context.LotteryActivities.AddAsync(activity); } public async Task UpdateAsync(LotteryActivity activity) { _context.LotteryActivities.Update(activity); await Task.CompletedTask; } public async Task DeleteAsync(LotteryActivity activity) { _context.LotteryActivities.Remove(activity); await Task.CompletedTask; } }