UserTaskService.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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.Identity.Entities;
  10. using MTWorkHR.Infrastructure.Repositories;
  11. using MTWorkHR.Infrastructure.UnitOfWorks;
  12. namespace MTWorkHR.Application.Services
  13. {
  14. public class UserTaskService : BaseService<UserTask, UserTaskDto, UserTaskDto>, IUserTaskService
  15. {
  16. private readonly IUnitOfWork _unitOfWork;
  17. //private readonly AppSettingsConfiguration _configuration;
  18. //private readonly GlobalInfo _globalInfo;
  19. private readonly IFileService _fileService;
  20. public UserTaskService(IUnitOfWork unitOfWork, IFileService fileService) : base(unitOfWork)
  21. {
  22. _unitOfWork = unitOfWork;
  23. _fileService = fileService;
  24. }
  25. //public override async Task<ProjectDto> GetById(long id)
  26. //{
  27. // var entity = await _unitOfWork.Project.GetByIdAsync(id);
  28. // var response = MapperObject.Mapper.Map<ProjectDto>(entity);
  29. // return response;
  30. //}
  31. //public override async Task<List<ProjectDto>> GetAll()
  32. //{
  33. // var projects = await _unitOfWork.Project.GetAllAsync();
  34. // var response = MapperObject.Mapper.Map<List<ProjectDto>>(projects);
  35. // return response;
  36. //}
  37. public override async Task<UserTaskDto> Create(UserTaskDto input)
  38. {
  39. if(input.TaskAttachments?.Count > 0)
  40. if ( !await _fileService.CopyFileToActualFolder(input.TaskAttachments.ToList()))
  41. throw new AppException(ExceptionEnum.CouldNotMoveFiles);
  42. var entity = Mapper.MapperObject.Mapper.Map<UserTask>(input);
  43. if (entity is null)
  44. {
  45. throw new AppException(ExceptionEnum.MapperIssue);
  46. }
  47. var task = await _unitOfWork.UserTask.AddAsync(entity);
  48. await _unitOfWork.CompleteAsync();
  49. var response = Mapper.MapperObject.Mapper.Map<UserTaskDto>(task);
  50. return response;
  51. }
  52. }
  53. }