From 4e4cc5567bb1e751b6fcbfb3258e50cbda22c20c Mon Sep 17 00:00:00 2001 From: Ruidy Nemausat Date: Mon, 17 Feb 2020 20:57:06 +0100 Subject: [PATCH] unit of work done --- Data/Interfaces/IUnitOfWork.cs | 11 +++++++++++ Data/UnitOfWork.cs | 27 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 Data/Interfaces/IUnitOfWork.cs create mode 100644 Data/UnitOfWork.cs 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