LogService.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Reflection;
  7. using MTWorkHR.Application.Services.Interfaces;
  8. using MTWorkHR.Core.UnitOfWork;
  9. using MTWorkHR.Core.IRepositories.Base;
  10. namespace MTWorkHR.Application.Services
  11. {
  12. public class LogService<TEntity>: ILogService<TEntity> where TEntity : class
  13. {
  14. private readonly IUnitOfWorkLog unitOfWork;
  15. //private readonly IRepository<TEntity> repository;
  16. public LogService(IUnitOfWorkLog _unitOfWork)
  17. {
  18. unitOfWork = _unitOfWork;
  19. //this.repository = repository;
  20. //repository = (IRepository<TEntity>)unitOfWork.GetRepositoryByName(typeof(TEntity).Name);
  21. }
  22. public virtual async Task Create(TEntity input)
  23. {
  24. IRepositoryLog<TEntity> repository = (IRepositoryLog<TEntity>)unitOfWork.GetRepositoryByName(input.GetType().Name);
  25. //var repository = (IRepository<TEntity>)value;
  26. await repository.AddAsync(input);
  27. await unitOfWork.CompleteAsync();
  28. }
  29. }
  30. }