using MTWorkHR.Core.Entities; using MTWorkHR.Core.IRepositories.Base; using MTWorkHR.Core.UnitOfWork; using MTWorkHR.Infrastructure.DBContext; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace MTWorkHR.Infrastructure.UnitOfWorks { public class UnitOfWorkLog : IUnitOfWorkLog { private readonly HRDataContext context; public IRepositoryLog UserLog { get; } public IRepositoryLog AuthLog { get; } public IRepositoryLog FileLog { get; } public IRepositoryLog RoleLog { get; } public IRepositoryLog SettingLog { get; } public IRepositoryLog UserTaskLog { get; } public IRepositoryLog TeamLog { get; } public IRepositoryLog MeetingLog { get; } public IRepositoryLog AttendanceLog { get; } public UnitOfWorkLog(HRDataContext _context , IRepositoryLog userLog , IRepositoryLog authenticateLog , IRepositoryLog FileLog , IRepositoryLog RoleLog , IRepositoryLog settingLog , IRepositoryLog userTaskLog , IRepositoryLog teamLog , IRepositoryLog meetingLog , IRepositoryLog attendanceLog ) { context = _context; UserLog = userLog; AuthLog = authenticateLog; this.FileLog = FileLog; this.RoleLog = RoleLog; this.SettingLog = settingLog; this.UserTaskLog = userTaskLog; this.TeamLog = teamLog; this.MeetingLog = meetingLog; this.AttendanceLog = attendanceLog; } public async Task CompleteAsync() { return await context.SaveChangesAsync(); } public object GetRepositoryByName(string name) { Type type = this.GetType(); PropertyInfo info = type.GetProperty(name); if (info == null) throw new Exception(String.Format( "A property called {0} can't be accessed for type {1}.", name, type.FullName)); var value = info.GetValue(this, null); // value = Convert.ChangeType(value, type); return value; } } }