LogService.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. using MTWorkHR.Application.Models;
  11. using MTWorkHR.Core.Entities;
  12. namespace MTWorkHR.Application.Services
  13. {
  14. public class LogService<TEntity> : ILogService<TEntity> where TEntity : class
  15. {
  16. private readonly IUnitOfWorkLog unitOfWork;
  17. private readonly IRepositoryLog<TEntity> repository;
  18. public LogService(IUnitOfWorkLog _unitOfWork)
  19. {
  20. unitOfWork = _unitOfWork;
  21. //this.repository = repository;
  22. repository = (IRepositoryLog<TEntity>)unitOfWork.GetRepositoryByName(typeof(TEntity).Name);
  23. }
  24. public virtual async Task Create(TEntity input)
  25. {
  26. IRepositoryLog<TEntity> repository = (IRepositoryLog<TEntity>)unitOfWork.GetRepositoryByName(input.GetType().Name);
  27. //var repository = (IRepository<TEntity>)value;
  28. await repository.AddAsync(input);
  29. await unitOfWork.CompleteAsync();
  30. }
  31. public virtual async Task<PagingResultDto<TEntity>> GetAll(PagingInputDto pagingInputDto)
  32. {
  33. var result = await repository.GetAllAsync(pagingInputDto);
  34. var list = Mapper.MapperObject.Mapper.Map<IList<TEntity>>(result.Item1);
  35. var response = new PagingResultDto<TEntity>
  36. {
  37. Result = list,
  38. Total = result.Item2
  39. };
  40. return response;
  41. }
  42. }
  43. }