UnitOfWorkLog.cs 2.5 KB

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