initial commit
This commit is contained in:
32
Repositories/PetRepository.cs
Normal file
32
Repositories/PetRepository.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user