Files
2026-04-07 13:11:39 -05:00

61 lines
1.9 KiB
C#

using LCU.API.Internal.MemberPreferencesApiLib.Persistence;
using LCU.Library.Internal.MemberPreferencesApiModels.Entities;
using LCU.Library.Internal.MemberPreferencesApiModels.Enums;
using Microsoft.EntityFrameworkCore;
namespace LCU.API.Internal.MemberPreferencesApiLib.Repositories;
public class XdiBatchItemsRepository : BaseRepository, IXdiBatchItemsRepository
{
public XdiBatchItemsRepository(IApplicationDbContext context) : base(context)
{
}
public async Task<IReadOnlyCollection<XdiBatchItem>> GetXdiBatchItems()
{
return await _context.XdiBatchItems.ToListAsync();
}
public async Task<IReadOnlyCollection<XdiBatchItem>> GetNewXdiBatchItems()
{
return await _context.XdiBatchItems.Where(x => x.BatchState == BatchState.New).ToListAsync();
}
public async Task<XdiBatchItem> SaveAsync(XdiBatchItem batchItem)
{
await _context.XdiBatchItems.AddAsync(batchItem);
return batchItem;
}
public async Task<List<XdiBatchItem>> SaveRangeAsync(List<XdiBatchItem> batchItemList)
{
await _context.XdiBatchItems.AddRangeAsync(batchItemList);
return batchItemList;
}
public async Task<XdiBatchItem> FindExistingItem(string userId, BatchState batchState)
{
return await _context.XdiBatchItems.Where(p => p.UserId == userId && p.BatchState == batchState)
.FirstOrDefaultAsync();
}
public void Update(XdiBatchItem existing)
{
_context.XdiBatchItems.Update(existing);
}
public void Delete(XdiBatchItem item)
{
_context.XdiBatchItems.Remove(item);
}
public async Task<bool> MarkPendingSuccessful(List<string> memberList)
{
var items = await _context.XdiBatchItems
.Where(x => x.BatchState == BatchState.TransferPending && memberList.Contains(x.UserId))
.ToListAsync();
_context.XdiBatchItems.RemoveRange(items);
return true;
}
}