UnitOfWorkLog.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using MTWorkHR.Core.Entities;
  2. using MTWorkHR.Core.IRepositories.Base;
  3. using MTWorkHR.Core.UnitOfWork;
  4. using MTWorkHR.Infrastructure.Data;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace MTWorkHR.Infrastructure.UnitOfWorks
  12. {
  13. public class UnitOfWorkLog : IUnitOfWorkLog
  14. {
  15. private readonly HRDataContext context;
  16. public IRepositoryLog<UserLog> UserLog { get; }
  17. public IRepositoryLog<AuthLog> AuthLog { get; }
  18. public IRepositoryLog<FileLog> FileLog { get; }
  19. public IRepositoryLog<RoleLog> RoleLog { get; }
  20. public IRepositoryLog<SettingLog> SettingLog { get; }
  21. public UnitOfWorkLog(HRDataContext _context
  22. , IRepositoryLog<UserLog> userLog
  23. , IRepositoryLog<AuthLog> authenticateLog
  24. , IRepositoryLog<FileLog> FileLog
  25. , IRepositoryLog<RoleLog> RoleLog
  26. , IRepositoryLog<SettingLog> settingLog
  27. )
  28. {
  29. context = _context;
  30. UserLog = userLog;
  31. AuthLog = authenticateLog;
  32. this.FileLog = FileLog;
  33. this.RoleLog = RoleLog;
  34. this.SettingLog = settingLog;
  35. }
  36. public async Task<int> CompleteAsync()
  37. {
  38. return await context.SaveChangesAsync();
  39. }
  40. public object GetRepositoryByName(string name)
  41. {
  42. Type type = this.GetType();
  43. PropertyInfo info = type.GetProperty(name);
  44. if (info == null)
  45. throw new Exception(String.Format(
  46. "A property called {0} can't be accessed for type {1}.",
  47. name, type.FullName));
  48. var value = info.GetValue(this, null);
  49. // value = Convert.ChangeType(value, type);
  50. return value;
  51. }
  52. }
  53. }