33 lines
788 B
C#
33 lines
788 B
C#
using Microsoft.EntityFrameworkCore;
|
|
using pet_companion_api.Data;
|
|
using pet_companion_api.Models;
|
|
|
|
namespace pet_companion_api.Repositories
|
|
{
|
|
public class PetRepository
|
|
{
|
|
private readonly ApplicationDbContext _context;
|
|
|
|
public PetRepository(ApplicationDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public IEnumerable<Pet> GetPetsByUserId(string userId)
|
|
{
|
|
return _context.Pets
|
|
.Where(p => p.UserId == userId)
|
|
.Include(p => p.Stats)
|
|
.Include(p => p.Resources)
|
|
.ToList();
|
|
}
|
|
|
|
public Pet CreatePet(Pet pet)
|
|
{
|
|
_context.Pets.Add(pet);
|
|
_context.SaveChanges();
|
|
return pet;
|
|
}
|
|
}
|
|
}
|