48 lines
1.1 KiB
C#
48 lines
1.1 KiB
C#
using PetCompanion.Data;
|
|
using PetCompanion.Models;
|
|
|
|
namespace PetCompanion.Repositories
|
|
{
|
|
public class GameItemsRepository
|
|
{
|
|
private readonly ApplicationDbContext _context;
|
|
|
|
public GameItemsRepository(ApplicationDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public GameItem GetById(int id)
|
|
{
|
|
return _context.GameItems.Find(id);
|
|
}
|
|
|
|
public IEnumerable<GameItem> GetAll()
|
|
{
|
|
return _context.GameItems;
|
|
}
|
|
|
|
public byte[] GetItemIcon(int itemId)
|
|
{
|
|
if (_context.GameItems.Find(itemId) == null)
|
|
{
|
|
throw new Exception("Item not found");
|
|
}
|
|
|
|
return File.ReadAllBytes($"game-data/item/icons/{itemId}.png");
|
|
}
|
|
|
|
public void Add(GameItem item)
|
|
{
|
|
_context.GameItems.Add(item);
|
|
_context.SaveChanges();
|
|
}
|
|
|
|
public void Update(GameItem item)
|
|
{
|
|
_context.GameItems.Update(item);
|
|
_context.SaveChanges();
|
|
}
|
|
}
|
|
}
|