diff --git a/Data/Interfaces/IUnitOfWork.cs b/Data/Interfaces/IUnitOfWork.cs new file mode 100644 index 0000000..6a614f3 --- /dev/null +++ b/Data/Interfaces/IUnitOfWork.cs @@ -0,0 +1,11 @@ +using System; +using System.Threading.Tasks; + +namespace TicketManager.Data +{ + public interface IUnitOfWork : IDisposable + { + IProjectRepository Projects { get; } + Task Complete(); + } +} \ No newline at end of file diff --git a/Data/UnitOfWork.cs b/Data/UnitOfWork.cs new file mode 100644 index 0000000..ad82b8b --- /dev/null +++ b/Data/UnitOfWork.cs @@ -0,0 +1,27 @@ +using System; +using System.Threading.Tasks; + +namespace TicketManager.Data +{ + public class UnitOfWork : IUnitOfWork + { + private readonly AppDbContext _context; + public UnitOfWork(AppDbContext context) + { + _context = context; + Projects = new ProjectRepository(_context); + } + + public IProjectRepository Projects { get; private set; } + + public async Task Complete() + { + return await _context.SaveChangesAsync(); + } + + public void Dispose() + { + _context.DisposeAsync(); + } + } +} \ No newline at end of file