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> GetXdiBatchItems() { return await _context.XdiBatchItems.ToListAsync(); } public async Task> GetNewXdiBatchItems() { return await _context.XdiBatchItems.Where(x => x.BatchState == BatchState.New).ToListAsync(); } public async Task SaveAsync(XdiBatchItem batchItem) { await _context.XdiBatchItems.AddAsync(batchItem); return batchItem; } public async Task 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 MarkPendingSuccessful(List memberList) { var items = await _context.XdiBatchItems .Where(x => x.BatchState == BatchState.TransferPending && memberList.Contains(x.UserId)) .ToListAsync(); _context.XdiBatchItems.RemoveRange(items); return true; } }