UserTaskAttachmentService.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. 
  2. using MTWorkHR.Application.Models;
  3. using MTWorkHR.Core.UnitOfWork;
  4. using MTWorkHR.Application.Services.Interfaces;
  5. using MTWorkHR.Core.Entities;
  6. using Microsoft.AspNetCore.Identity;
  7. using MTWorkHR.Application.Mapper;
  8. using MTWorkHR.Core.Global;
  9. using MTWorkHR.Infrastructure.Entities;
  10. using MTWorkHR.Infrastructure.Repositories;
  11. using MTWorkHR.Infrastructure.UnitOfWorks;
  12. using MTWorkHR.Core.IRepositories.Base;
  13. namespace MTWorkHR.Application.Services
  14. {
  15. public class UserTaskAttachmentService : BaseService<UserTaskAttachment, AttachmentDto, AttachmentDto>, IUserTaskAttachmentService
  16. {
  17. private readonly IUnitOfWork _unitOfWork;
  18. //private readonly AppSettingsConfiguration _configuration;
  19. //private readonly GlobalInfo _globalInfo;
  20. private readonly IFileService _fileService;
  21. public UserTaskAttachmentService(IUnitOfWork unitOfWork, IFileService fileService) : base(unitOfWork)
  22. {
  23. _unitOfWork = unitOfWork;
  24. _fileService = fileService;
  25. }
  26. public override async Task<AttachmentDto> GetById(long id)
  27. {
  28. var entity = await _unitOfWork.UserTaskAttachment.GetByIdAsync(id);
  29. var response = MapperObject.Mapper.Map<AttachmentDto>(entity);
  30. return response;
  31. }
  32. public override async Task<AttachmentDto> Create(AttachmentDto input)
  33. {
  34. if (input.FileData != null)
  35. input.FileName = await _fileService.UploadFile(input.FileData);
  36. var entity = MapperObject.Mapper.Map<UserTaskAttachment>(input);
  37. if (entity is null)
  38. {
  39. throw new AppException(ExceptionEnum.MapperIssue);
  40. }
  41. var task = await _unitOfWork.UserTaskAttachment.AddAsync(entity);
  42. await _unitOfWork.CompleteAsync();
  43. var response = MapperObject.Mapper.Map<AttachmentDto>(task);
  44. return response;
  45. }
  46. //public override async Task<AttachmentDto> Update(AttachmentDto input)
  47. //{
  48. // var entitiy = await _unitOfWork.UserTaskAttachment.GetByIdAsync(input.Id);
  49. // if (entitiy == null)
  50. // throw new AppException(ExceptionEnum.RecordNotExist);
  51. // MapperObject.Mapper.Map(input, entitiy, typeof(AttachmentDto), typeof(UserTaskAttachment));
  52. // await _unitOfWork.CompleteAsync();
  53. // return input;
  54. //}
  55. }
  56. }