UnitOfWork.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // ======================================
  2. // Author: Ebenezer Monney
  3. // Email: info@ebenmonney.com
  4. // Copyright (c) 2017 www.ebenmonney.com
  5. //
  6. // ==> Gun4Hire: contact@ebenmonney.com
  7. // ======================================
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using DAL.Repositories;
  14. using DAL.Repositories.Interfaces;
  15. namespace DAL
  16. {
  17. public class UnitOfWork : IUnitOfWork
  18. {
  19. readonly ApplicationDbContext _context;
  20. ICustomerRepository _customers;
  21. IProductRepository _products;
  22. IOrdersRepository _orders;
  23. public UnitOfWork(ApplicationDbContext context)
  24. {
  25. _context = context;
  26. }
  27. public ICustomerRepository Customers
  28. {
  29. get
  30. {
  31. if (_customers == null)
  32. _customers = new CustomerRepository(_context);
  33. return _customers;
  34. }
  35. }
  36. public IProductRepository Products
  37. {
  38. get
  39. {
  40. if (_products == null)
  41. _products = new ProductRepository(_context);
  42. return _products;
  43. }
  44. }
  45. public IOrdersRepository Orders
  46. {
  47. get
  48. {
  49. if (_orders == null)
  50. _orders = new OrdersRepository(_context);
  51. return _orders;
  52. }
  53. }
  54. public int SaveChanges()
  55. {
  56. return _context.SaveChanges();
  57. }
  58. }
  59. }