Add action gathering functionality: implement ActionGathered model and repository, update Pet model and services, and enhance GameItemsRepository with item retrieval methods.
This commit is contained in:
47
Repositories/ActionGatheredRepository.cs
Normal file
47
Repositories/ActionGatheredRepository.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
@@ -17,6 +17,11 @@ namespace PetCompanion.Repositories
|
||||
return _context.GameItems.Find(id);
|
||||
}
|
||||
|
||||
public IEnumerable<GameItem> GetAll()
|
||||
{
|
||||
return _context.GameItems;
|
||||
}
|
||||
|
||||
public void Add(GameItem item)
|
||||
{
|
||||
_context.GameItems.Add(item);
|
||||
|
@@ -21,6 +21,18 @@ namespace PetCompanion.Repositories
|
||||
.Include(p => p.Resources)
|
||||
.Include(p => p.Inventory)
|
||||
.Include(p => p.EquippedItemsList)
|
||||
.Include(p => p.ActionGathered)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public IEnumerable<Pet> GetPetWithActions()
|
||||
{
|
||||
return context.Pets
|
||||
.Where(predicate => predicate.PetGatherAction != PetActionGather.IDLE)
|
||||
.Include(p => p.Stats)
|
||||
.Include(p => p.Resources)
|
||||
.Include(p => p.Inventory)
|
||||
.Include(p => p.EquippedItemsList)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@@ -32,6 +44,7 @@ namespace PetCompanion.Repositories
|
||||
.Include(p => p.Resources)
|
||||
.Include(p => p.Inventory)
|
||||
.Include(p => p.EquippedItemsList)
|
||||
.Include(p => p.ActionGathered)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user