|
@@ -9,14 +9,13 @@ using Microsoft.EntityFrameworkCore;
|
|
|
using System.Linq.Dynamic.Core;
|
|
|
using MTWorkHR.Core.IDto;
|
|
|
using MTWorkHR.Application.Identity;
|
|
|
+using MTWorkHR.Core.Entities.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;
|
|
|
private readonly GlobalInfo _globalInfo;
|
|
|
private readonly IUserService _userService;
|
|
@@ -34,12 +33,16 @@ namespace MTWorkHR.Application.Services
|
|
|
{
|
|
|
var entity = await _unitOfWork.UserTask.GetByIdWithAllChildren(id);
|
|
|
var response = MapperObject.Mapper.Map<UserTaskDto>(entity);
|
|
|
+ await GetUserData(response);
|
|
|
return response;
|
|
|
}
|
|
|
public async Task<UserTaskDto> GetByUserId(string userId)
|
|
|
{
|
|
|
var entity = await _unitOfWork.UserTask.GetByUserIdWithAllChildren(userId);
|
|
|
+
|
|
|
var response = MapperObject.Mapper.Map<UserTaskDto>(entity);
|
|
|
+ await GetUserData(response);
|
|
|
+
|
|
|
return response;
|
|
|
}
|
|
|
|
|
@@ -110,9 +113,12 @@ namespace MTWorkHR.Application.Services
|
|
|
|
|
|
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);
|
|
|
+ if (input.TaskAttachments?.Count > 0)
|
|
|
+ {
|
|
|
+ var attachs = input.TaskAttachments.ToList();
|
|
|
+ _fileService.CopyFileToCloud(ref attachs);
|
|
|
+ }
|
|
|
+
|
|
|
var entity = MapperObject.Mapper.Map<UserTask>(input);
|
|
|
if (entity is null)
|
|
|
{
|
|
@@ -123,22 +129,48 @@ namespace MTWorkHR.Application.Services
|
|
|
await _unitOfWork.CompleteAsync();
|
|
|
|
|
|
var response = MapperObject.Mapper.Map<UserTaskDto>(task);
|
|
|
+ await GetUserData(response);
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
+ private async Task GetUserData(UserTaskDto response)
|
|
|
+ {
|
|
|
+ if (response.AssignedUserId != null)
|
|
|
+ {
|
|
|
+ var user = await _userService.GetUserWithAttachmentById(response.AssignedUserId);
|
|
|
+ if (user != null)
|
|
|
+ {
|
|
|
+ response.AssignedUserName = user.FirstName + " " + user.LastName;
|
|
|
+ var image = user.UserAttachments?.FirstOrDefault(a => a.AttachmentTypeId == 9);
|
|
|
+ response.ProfileImage = image != null ? image.FilePath : "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
public override async Task<UserTaskDto> Update(UserTaskDto input)
|
|
|
{
|
|
|
- var entitiy = await _unitOfWork.UserTask.GetByIdAsync(input.Id);
|
|
|
+ var entity = await _unitOfWork.UserTask.GetByIdAsync(input.Id);
|
|
|
|
|
|
- if (entitiy == null)
|
|
|
+ if (entity == null)
|
|
|
throw new AppException(ExceptionEnum.RecordNotExist);
|
|
|
|
|
|
- MapperObject.Mapper.Map(input, entitiy, typeof(UserTaskDto), typeof(UserTask));
|
|
|
+ MapperObject.Mapper.Map(input, entity, typeof(UserTaskDto), typeof(UserTask));
|
|
|
|
|
|
await _unitOfWork.CompleteAsync();
|
|
|
+ var response = Mapper.MapperObject.Mapper.Map<UserTaskDto>(entity);
|
|
|
+ await GetUserData(response);
|
|
|
+
|
|
|
+ return response;
|
|
|
+ }
|
|
|
|
|
|
- return input;
|
|
|
+ public async Task ChangeStatus(long taskId, int statusId)
|
|
|
+ {
|
|
|
+ var entity = await _unitOfWork.UserTask.GetByIdAsync(taskId);
|
|
|
+ if (entity == null)
|
|
|
+ throw new AppException(ExceptionEnum.RecordNotExist);
|
|
|
+ entity.StatusId = statusId;
|
|
|
+
|
|
|
+ await _unitOfWork.CompleteAsync();
|
|
|
}
|
|
|
}
|
|
|
}
|