UserTaskAttachmentService.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. using Microsoft.AspNetCore.Http;
  14. using System.IO;
  15. namespace MTWorkHR.Application.Services
  16. {
  17. public class UserTaskAttachmentService : BaseService<UserTaskAttachment, AttachmentDto, AttachmentDto>, IUserTaskAttachmentService
  18. {
  19. private readonly IUnitOfWork _unitOfWork;
  20. //private readonly AppSettingsConfiguration _configuration;
  21. //private readonly GlobalInfo _globalInfo;
  22. private readonly IFileService _fileService;
  23. public UserTaskAttachmentService(IUnitOfWork unitOfWork, IFileService fileService) : base(unitOfWork)
  24. {
  25. _unitOfWork = unitOfWork;
  26. _fileService = fileService;
  27. }
  28. public override async Task<AttachmentDto> GetById(long id)
  29. {
  30. var entity = await _unitOfWork.UserTaskAttachment.GetByIdAsync(id);
  31. var response = MapperObject.Mapper.Map<AttachmentDto>(entity);
  32. return response;
  33. }
  34. public override async Task<AttachmentDto> Create(AttachmentDto input)
  35. {
  36. //if (input.FileData != null)
  37. //{
  38. // // input.FilePath = await _fileService.UploadFile(input.FileData);
  39. // input.OriginalName = input.FileData.FileName;
  40. // List<AttachmentDto> attachs = new List<AttachmentDto>();
  41. // attachs.Add(input);
  42. // _fileService.CopyFileToCloud(ref attachs);
  43. //}
  44. var entity = MapperObject.Mapper.Map<UserTaskAttachment>(input);
  45. if (entity is null)
  46. {
  47. throw new AppException(ExceptionEnum.MapperIssue);
  48. }
  49. var task = await _unitOfWork.UserTaskAttachment.AddAsync(entity);
  50. await _unitOfWork.CompleteAsync();
  51. var response = MapperObject.Mapper.Map<AttachmentDto>(task);
  52. return response;
  53. }
  54. public override async Task<AttachmentDto> Update(AttachmentDto input)
  55. {
  56. var entitiy = await _unitOfWork.UserTaskAttachment.GetByIdAsync(input.Id);
  57. if (entitiy == null)
  58. throw new AppException(ExceptionEnum.RecordNotExist);
  59. MapperObject.Mapper.Map(input, entitiy, typeof(AttachmentDto), typeof(UserTaskAttachment));
  60. await _unitOfWork.CompleteAsync();
  61. return input;
  62. }
  63. }
  64. }