UserTaskAttachmentService.cs 3.3 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 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. //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<AttachmentDto> Update(AttachmentDto input)
  68. //{
  69. // var entitiy = await _unitOfWork.UserTaskAttachment.GetByIdAsync(input.Id);
  70. // if (entitiy == null)
  71. // throw new AppException(ExceptionEnum.RecordNotExist);
  72. // MapperObject.Mapper.Map(input, entitiy, typeof(AttachmentDto), typeof(UserTaskAttachment));
  73. // await _unitOfWork.CompleteAsync();
  74. // return input;
  75. //}
  76. }
  77. }