12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
-
- using MTWorkHR.Application.Models;
- using MTWorkHR.Core.UnitOfWork;
- using MTWorkHR.Application.Services.Interfaces;
- using MTWorkHR.Core.Entities;
- using Microsoft.AspNetCore.Identity;
- using MTWorkHR.Application.Mapper;
- using MTWorkHR.Core.Global;
- using MTWorkHR.Infrastructure.Entities;
- using MTWorkHR.Infrastructure.Repositories;
- using MTWorkHR.Infrastructure.UnitOfWorks;
- using MTWorkHR.Core.IRepositories.Base;
- namespace MTWorkHR.Application.Services
- {
- public class UserTaskService : BaseService<UserTask, UserTaskDto, UserTaskDto>, IUserTaskService
- {
- private readonly IUnitOfWork _unitOfWork;
- //private readonly AppSettingsConfiguration _configuration;
- //private readonly GlobalInfo _globalInfo;
- private readonly IFileService _fileService;
- public UserTaskService(IUnitOfWork unitOfWork, IFileService fileService) : base(unitOfWork)
- {
- _unitOfWork = unitOfWork;
- _fileService = fileService;
- }
- public override async Task<UserTaskDto> GetById(long id)
- {
- var entity = await _unitOfWork.UserTask.GetByIdWithAllChildren(id);
- var response = MapperObject.Mapper.Map<UserTaskDto>(entity);
- return response;
- }
- public async Task<UserTaskDto> GetByUserId(long userId)
- {
- var entity = await _unitOfWork.UserTask.GetByUserIdWithAllChildren(userId);
- var response = MapperObject.Mapper.Map<UserTaskDto>(entity);
- return response;
- }
- //public override async Task<List<ProjectDto>> GetAll()
- //{
- // var projects = await _unitOfWork.Project.GetAllAsync();
- // var response = MapperObject.Mapper.Map<List<ProjectDto>>(projects);
- // return response;
- //}
- public override async Task<UserTaskDto> Create(UserTaskDto input)
- {
- if(input.TaskAttachments?.Count > 0)
- if ( !await _fileService.CopyFileToActualFolder(input.TaskAttachments.ToList()))
- throw new AppException(ExceptionEnum.CouldNotMoveFiles);
- var entity = MapperObject.Mapper.Map<UserTask>(input);
- if (entity is null)
- {
- throw new AppException(ExceptionEnum.MapperIssue);
- }
- var task = await _unitOfWork.UserTask.AddAsync(entity);
- await _unitOfWork.CompleteAsync();
- var response = MapperObject.Mapper.Map<UserTaskDto>(task);
- return response;
- }
- public override async Task<UserTaskDto> Update(UserTaskDto input)
- {
- var entitiy = await _unitOfWork.UserTask.GetByIdAsync(input.Id);
- if (entitiy == null)
- throw new AppException(ExceptionEnum.RecordNotExist);
- MapperObject.Mapper.Map(input, entitiy, typeof(UserTaskDto), typeof(UserTask));
- await _unitOfWork.CompleteAsync();
- return input;
- }
- }
- }
|