using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using TOOHUCardAPI.Data.Models; namespace TOOHUCardAPI.Data.Repositories { public class CardRepository { private readonly AppDbContext _context; public CardRepository(AppDbContext context) { _context = context; } public async Task GetCardByItemCode(string itemCode, bool allowNull = false) { Card card = await _context.Cards.FirstOrDefaultAsync(card => card.ItemCode == itemCode); if (card == null && !allowNull) { throw new InvalidCardException(); } return card; } public async Task> GetAllCards() { return await _context.Cards.ToListAsync(); } } }