59 lines
1.7 KiB
C#
59 lines
1.7 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Fengling.RiskControl.Domain.Aggregates.RiskScores;
|
|
using Fengling.RiskControl.Domain.Repositories;
|
|
|
|
namespace Fengling.RiskControl.Infrastructure.Repositories;
|
|
|
|
public class RiskScoreRepository : IRiskScoreRepository
|
|
{
|
|
private readonly RiskControlDbContext _context;
|
|
|
|
public RiskScoreRepository(RiskControlDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<RiskScore?> GetByIdAsync(long id)
|
|
{
|
|
return await _context.RiskScores.FindAsync(id);
|
|
}
|
|
|
|
public async Task<RiskScore?> GetByMemberAndEntityAsync(long memberId, string entityType, string entityId)
|
|
{
|
|
return await _context.RiskScores
|
|
.FirstOrDefaultAsync(s => s.MemberId == memberId && s.EntityType == entityType && s.EntityId == entityId);
|
|
}
|
|
|
|
public async Task<RiskScore?> GetActiveByMemberAndEntityTypeAsync(long memberId, string entityType)
|
|
{
|
|
return await _context.RiskScores
|
|
.Where(s => s.MemberId == memberId && s.EntityType == entityType)
|
|
.OrderByDescending(s => s.CreatedAt)
|
|
.FirstOrDefaultAsync();
|
|
}
|
|
|
|
public async Task<IEnumerable<RiskScore>> GetByMemberIdAsync(long memberId)
|
|
{
|
|
return await _context.RiskScores
|
|
.Where(s => s.MemberId == memberId)
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task AddAsync(RiskScore score)
|
|
{
|
|
await _context.RiskScores.AddAsync(score);
|
|
}
|
|
|
|
public async Task UpdateAsync(RiskScore score)
|
|
{
|
|
_context.RiskScores.Update(score);
|
|
await Task.CompletedTask;
|
|
}
|
|
|
|
public async Task DeleteAsync(RiskScore score)
|
|
{
|
|
_context.RiskScores.Remove(score);
|
|
await Task.CompletedTask;
|
|
}
|
|
}
|