pet-companion-back/Repositories/ActionGatheredRepository.cs

48 lines
1.4 KiB
C#

using PetCompanion.Data;
using PetCompanion.Models;
using Microsoft.EntityFrameworkCore;
namespace PetCompanion.Repositories
{
public class ActionGatheredRepository
{
private readonly ApplicationDbContext _context;
public ActionGatheredRepository(ApplicationDbContext context)
{
_context = context;
}
public IEnumerable<ActionGathered> GetAllActionGatheredByPetId(string petId)
{
return _context.ActionGathered
.Where(ag => ag.PetId == petId)
.Include(ag => ag.GameItem)
.ToList();
}
public ActionGathered CreateActionGathered(ActionGathered actionGathered)
{
var entry = _context.ActionGathered.Add(actionGathered);
_context.SaveChanges();
return entry.Entity;
}
public ActionGathered UpdateActionGathered(ActionGathered actionGathered)
{
var entry = _context.ActionGathered.Update(actionGathered);
_context.SaveChanges();
return entry.Entity;
}
public void DeleteAllActionGatheredByPetId(string petId)
{
var actionsToDelete = _context.ActionGathered
.Where(ag => ag.PetId == petId);
_context.ActionGathered.RemoveRange(actionsToDelete);
_context.SaveChanges();
}
}
}