UserTaskService.cs 2.6 KB

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