First table in database
This commit is contained in:
42
GerbilManagerWebAPI/Repositories/EFGerbilRepository.cs
Normal file
42
GerbilManagerWebAPI/Repositories/EFGerbilRepository.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using GerbilManagerWebAPI.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace GerbilManagerWebAPI.Repositories
|
||||
{
|
||||
public class EFGerbilRepository : IGerbilRepository
|
||||
{
|
||||
private readonly ApplicationContext context;
|
||||
public EFGerbilRepository(ApplicationContext context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void CreateGerbil(Gerbil gerbil)
|
||||
{
|
||||
context.Gerbils.Add(gerbil);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
public void DeleteGerbil(Gerbil gerbil)
|
||||
{
|
||||
context.Gerbils.Remove(gerbil);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
public Gerbil GetGerbil(Guid id)
|
||||
{
|
||||
return context.Gerbils.Where(entity => entity.Id == id).First();
|
||||
}
|
||||
|
||||
public IEnumerable<Gerbil> GetGerbils()
|
||||
{
|
||||
return context.Gerbils.ToList();
|
||||
}
|
||||
|
||||
public void UpdateGerbil(Gerbil gerbil)
|
||||
{
|
||||
context.Gerbils.Update(gerbil);
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user