79 lines
2.1 KiB
C#
79 lines
2.1 KiB
C#
using GerbilManagerWebAPI.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace GerbilManagerWebAPI.DAL
|
|
{
|
|
public class UnitOfWork : IDisposable
|
|
{
|
|
private ApplicationContext context;
|
|
private GenericRepository<Gerbil> gerbilRepository;
|
|
private GenericRepository<Litter> litterRepository;
|
|
private GenericRepository<Breeder> breederRepository;
|
|
|
|
public GenericRepository<Gerbil> GerbilRepository
|
|
{
|
|
get
|
|
{
|
|
if (this.gerbilRepository == null)
|
|
{
|
|
this.gerbilRepository = new GenericRepository<Gerbil>(context);
|
|
}
|
|
return gerbilRepository;
|
|
}
|
|
}
|
|
|
|
public GenericRepository<Litter> LitterRepository
|
|
{
|
|
get
|
|
{
|
|
if (this.litterRepository == null)
|
|
{
|
|
this.litterRepository = new GenericRepository<Litter>(context);
|
|
}
|
|
return litterRepository;
|
|
}
|
|
}
|
|
|
|
public GenericRepository<Breeder> BreederRepository
|
|
{
|
|
get
|
|
{
|
|
if (this.breederRepository == null)
|
|
{
|
|
this.breederRepository = new GenericRepository<Breeder>(context);
|
|
}
|
|
return breederRepository;
|
|
}
|
|
}
|
|
|
|
public UnitOfWork(ApplicationContext context)
|
|
{
|
|
this.context = context;
|
|
}
|
|
|
|
public void Save()
|
|
{
|
|
context.SaveChanges();
|
|
}
|
|
|
|
private bool disposed = false;
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
{
|
|
if (!this.disposed)
|
|
{
|
|
if (disposing)
|
|
{
|
|
context.Dispose();
|
|
}
|
|
}
|
|
this.disposed = true;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Dispose(true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
}
|
|
} |