27 lines
702 B
C#
27 lines
702 B
C#
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;
|
|
}
|
|
}
|
|
} |