60 lines
1.6 KiB
C#
60 lines
1.6 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Fengling.RiskControl.Domain.Aggregates.RiskAlerts;
|
|
using Fengling.RiskControl.Domain.Repositories;
|
|
|
|
namespace Fengling.RiskControl.Infrastructure.Repositories;
|
|
|
|
public class RiskAlertRepository : IRiskAlertRepository
|
|
{
|
|
private readonly RiskControlDbContext _context;
|
|
|
|
public RiskAlertRepository(RiskControlDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<RiskAlert?> GetByIdAsync(long id)
|
|
{
|
|
return await _context.RiskAlerts.FindAsync(id);
|
|
}
|
|
|
|
public async Task<IEnumerable<RiskAlert>> GetByMemberIdAsync(long memberId)
|
|
{
|
|
return await _context.RiskAlerts
|
|
.Where(a => a.MemberId == memberId)
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task<IEnumerable<RiskAlert>> GetPendingAlertsAsync()
|
|
{
|
|
return await _context.RiskAlerts
|
|
.Where(a => a.Status == RiskAlertStatus.Pending)
|
|
.OrderByDescending(a => a.Priority)
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task<IEnumerable<RiskAlert>> GetAlertsByPriorityAsync(RiskAlertPriority priority)
|
|
{
|
|
return await _context.RiskAlerts
|
|
.Where(a => a.Priority == priority)
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task AddAsync(RiskAlert alert)
|
|
{
|
|
await _context.RiskAlerts.AddAsync(alert);
|
|
}
|
|
|
|
public async Task UpdateAsync(RiskAlert alert)
|
|
{
|
|
_context.RiskAlerts.Update(alert);
|
|
await Task.CompletedTask;
|
|
}
|
|
|
|
public async Task DeleteAsync(RiskAlert alert)
|
|
{
|
|
_context.RiskAlerts.Remove(alert);
|
|
await Task.CompletedTask;
|
|
}
|
|
}
|