55 lines
1.6 KiB
C#
55 lines
1.6 KiB
C#
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<LotteryActivity?> GetByIdAsync(long id)
|
|
{
|
|
return await _context.LotteryActivities.FindAsync(id);
|
|
}
|
|
|
|
public async Task<IEnumerable<LotteryActivity>> GetByMemberIdAsync(long memberId)
|
|
{
|
|
return await _context.LotteryActivities
|
|
.Where(l => l.MemberId == memberId)
|
|
.OrderByDescending(l => l.CreatedAt)
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task<IEnumerable<LotteryActivity>> 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;
|
|
}
|
|
}
|