ContractTaskAttachmentService.cs 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 ContractTaskAttachmentService : BaseService<ContractTaskAttachment, ContractTaskAttachmentDto, ContractTaskAttachmentDto>, IContractTaskAttachmentService
  18. {
  19. private readonly IUnitOfWork _unitOfWork;
  20. //private readonly AppSettingsConfiguration _configuration;
  21. //private readonly GlobalInfo _globalInfo;
  22. private readonly IFileService _fileService;
  23. public ContractTaskAttachmentService(IUnitOfWork unitOfWork, IFileService fileService) : base(unitOfWork)
  24. {
  25. _unitOfWork = unitOfWork;
  26. _fileService = fileService;
  27. }
  28. public override async Task<ContractTaskAttachmentDto> GetById(long id)
  29. {
  30. var entity = await _unitOfWork.ContractTaskAttachment.GetByIdAsync(id);
  31. var response = MapperObject.Mapper.Map<ContractTaskAttachmentDto>(entity);
  32. return response;
  33. }
  34. public override async Task<ContractTaskAttachmentDto> Create(ContractTaskAttachmentDto 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(new AttachmentDto {FileData = input.FileData, OriginalName = input.OriginalName, FileName = input.FileData.FileName });
  42. _fileService.CopyFileToCloud(ref attachs);
  43. }
  44. var entity = MapperObject.Mapper.Map<ContractTaskAttachment>(input);
  45. if (entity is null)
  46. {
  47. throw new AppException(ExceptionEnum.MapperIssue);
  48. }
  49. var task = await _unitOfWork.ContractTaskAttachment.AddAsync(entity);
  50. await _unitOfWork.CompleteAsync();
  51. var response = MapperObject.Mapper.Map<ContractTaskAttachmentDto>(task);
  52. //using (var stream = new MemoryStream(attach.Content))
  53. //{
  54. // var file = new FormFile(stream, 0, stream.Length, Path.GetFileNameWithoutExtension(attach.FileName), attach.FileName)
  55. // {
  56. // Headers = new HeaderDictionary(),
  57. // ContentType = attach.ContentType,
  58. // };
  59. // System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition
  60. // {
  61. // FileName = file.FileName
  62. // };
  63. // file.ContentDisposition = cd.ToString();
  64. //}
  65. return response;
  66. }
  67. //public override async Task<ContractTaskAttachmentDto> Update(ContractTaskAttachmentDto input)
  68. //{
  69. // var entitiy = await _unitOfWork.ContractTaskAttachment.GetByIdAsync(input.Id);
  70. // if (entitiy == null)
  71. // throw new AppException(ExceptionEnum.RecordNotExist);
  72. // MapperObject.Mapper.Map(input, entitiy, typeof(ContractTaskAttachmentDto), typeof(ContractTaskAttachment));
  73. // await _unitOfWork.CompleteAsync();
  74. // return input;
  75. //}
  76. }
  77. }