Files
API/TOOHUCardAPI/Data/Repositories/CardRepository.cs

33 lines
871 B
C#

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<Card> 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<IEnumerable<Card>> GetAllCards()
{
return await _context.Cards.ToListAsync();
}
}
}