UnitOfWorkLog.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using MTWorkHR.Core.Entities;
  2. using MTWorkHR.Core.IRepositories.Base;
  3. using MTWorkHR.Core.UnitOfWork;
  4. using MTWorkHR.Infrastructure.DBContext;
  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 IRepositoryLog<UserTaskLog> UserTaskLog { get; }
  22. public IRepositoryLog<TeamLog> TeamLog { get; }
  23. public IRepositoryLog<MeetingLog> MeetingLog { get; }
  24. public UnitOfWorkLog(HRDataContext _context
  25. , IRepositoryLog<UserLog> userLog
  26. , IRepositoryLog<AuthLog> authenticateLog
  27. , IRepositoryLog<FileLog> FileLog
  28. , IRepositoryLog<RoleLog> RoleLog
  29. , IRepositoryLog<SettingLog> settingLog
  30. , IRepositoryLog<UserTaskLog> userTaskLog
  31. , IRepositoryLog<TeamLog> teamLog
  32. , IRepositoryLog<MeetingLog> meetingLog
  33. )
  34. {
  35. context = _context;
  36. UserLog = userLog;
  37. AuthLog = authenticateLog;
  38. this.FileLog = FileLog;
  39. this.RoleLog = RoleLog;
  40. this.SettingLog = settingLog;
  41. this.UserTaskLog = userTaskLog;
  42. this.TeamLog = teamLog;
  43. this.MeetingLog = meetingLog;
  44. }
  45. public async Task<int> CompleteAsync()
  46. {
  47. return await context.SaveChangesAsync();
  48. }
  49. public object GetRepositoryByName(string name)
  50. {
  51. Type type = this.GetType();
  52. PropertyInfo info = type.GetProperty(name);
  53. if (info == null)
  54. throw new Exception(String.Format(
  55. "A property called {0} can't be accessed for type {1}.",
  56. name, type.FullName));
  57. var value = info.GetValue(this, null);
  58. // value = Convert.ChangeType(value, type);
  59. return value;
  60. }
  61. }
  62. }