UnitOfWorkLog.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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<AuthenticateLog> AuthenticateLog { get; }
  18. public IRepositoryLog<FileLog> FileLog { get; }
  19. public IRepositoryLog<RoleLog> RoleLog { get; }
  20. public IRepositoryLog<SettingLog> SettingLog { get; }
  21. public IRepositoryLog<SmsLog> SmsLog { get; }
  22. public UnitOfWorkLog(HRDataContext _context
  23. , IRepositoryLog<UserLog> userLog
  24. , IRepositoryLog<AuthenticateLog> authenticateLog
  25. , IRepositoryLog<FileLog> FileLog
  26. , IRepositoryLog<RoleLog> RoleLog
  27. , IRepositoryLog<SettingLog> settingLog
  28. , IRepositoryLog<SmsLog> SmsLog
  29. )
  30. {
  31. context = _context;
  32. UserLog = userLog;
  33. AuthenticateLog = authenticateLog;
  34. this.FileLog = FileLog;
  35. this.RoleLog = RoleLog;
  36. this.SettingLog = settingLog;
  37. this.SmsLog = SmsLog;
  38. }
  39. public async Task<int> CompleteAsync()
  40. {
  41. return await context.SaveChangesAsync();
  42. }
  43. public object GetRepositoryByName(string name)
  44. {
  45. Type type = this.GetType();
  46. PropertyInfo info = type.GetProperty(name);
  47. if (info == null)
  48. throw new Exception(String.Format(
  49. "A property called {0} can't be accessed for type {1}.",
  50. name, type.FullName));
  51. var value = info.GetValue(this, null);
  52. // value = Convert.ChangeType(value, type);
  53. return value;
  54. }
  55. }
  56. }