Lots of additions and restructuring
This commit is contained in:
27
TOOHUCardAPI/Data/Repositories/CardRepository.cs
Normal file
27
TOOHUCardAPI/Data/Repositories/CardRepository.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user