|
@@ -12,20 +12,26 @@ using MTWorkHR.Infrastructure.UnitOfWorks;
|
|
|
using MTWorkHR.Core.IRepositories.Base;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using System.IO;
|
|
|
+using System.Linq.Dynamic.Core;
|
|
|
+using Microsoft.EntityFrameworkCore;
|
|
|
+using MTWorkHR.Application.Identity;
|
|
|
+
|
|
|
|
|
|
namespace MTWorkHR.Application.Services
|
|
|
{
|
|
|
public class UserTaskAttachmentService : BaseService<UserTaskAttachment, AttachmentDto, AttachmentDto>, IUserTaskAttachmentService
|
|
|
{
|
|
|
private readonly IUnitOfWork _unitOfWork;
|
|
|
- //private readonly AppSettingsConfiguration _configuration;
|
|
|
- //private readonly GlobalInfo _globalInfo;
|
|
|
+ private readonly IUserService _userService;
|
|
|
private readonly IFileService _fileService;
|
|
|
+ private readonly GlobalInfo _globalInfo;
|
|
|
|
|
|
- public UserTaskAttachmentService(IUnitOfWork unitOfWork, IFileService fileService) : base(unitOfWork)
|
|
|
+ public UserTaskAttachmentService(IUnitOfWork unitOfWork, IFileService fileService, GlobalInfo globalInfo, IUserService userService) : base(unitOfWork)
|
|
|
{
|
|
|
_unitOfWork = unitOfWork;
|
|
|
_fileService = fileService;
|
|
|
+ _globalInfo = globalInfo;
|
|
|
+ _userService = userService;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -36,6 +42,41 @@ namespace MTWorkHR.Application.Services
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
+ public override async Task<PagingResultDto<AttachmentDto>> GetAll(PagingInputDto PagingInputDto)
|
|
|
+ {
|
|
|
+ var res = await _unitOfWork.UserTaskAttachment.GetAllWithChildrenAsync();
|
|
|
+ var query = res.Item1;
|
|
|
+
|
|
|
+ if (PagingInputDto.Filter != null)
|
|
|
+ {
|
|
|
+ var filter = PagingInputDto.Filter;
|
|
|
+ query = query.Where(u => u.FileName.Contains(filter));
|
|
|
+ }
|
|
|
+
|
|
|
+ var order = query.OrderBy(PagingInputDto.OrderByField + " " + PagingInputDto.OrderType);
|
|
|
+
|
|
|
+ var page = order.Skip((PagingInputDto.PageNumber * PagingInputDto.PageSize) - PagingInputDto.PageSize).Take(PagingInputDto.PageSize);
|
|
|
+
|
|
|
+ var total = await query.CountAsync();
|
|
|
+
|
|
|
+ var list = MapperObject.Mapper
|
|
|
+ .Map<IList<AttachmentDto>>(await page.ToListAsync());
|
|
|
+ // Fetch user data for all employees
|
|
|
+ foreach (var attach in list)
|
|
|
+ {
|
|
|
+ var user = await _userService.GetUserNameEmail(attach.CreateUser);
|
|
|
+ attach.ProfileImage = user.ProfileImage;
|
|
|
+ attach.CreatedUserName = user.FullName;
|
|
|
+ }
|
|
|
+ var response = new PagingResultDto<AttachmentDto>
|
|
|
+ {
|
|
|
+ Result = list,
|
|
|
+ Total = total
|
|
|
+ };
|
|
|
+
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
public override async Task<AttachmentDto> Create(AttachmentDto input)
|
|
|
{
|
|
|
//if (input.FileData != null)
|
|
@@ -54,26 +95,33 @@ namespace MTWorkHR.Application.Services
|
|
|
throw new AppException(ExceptionEnum.MapperIssue);
|
|
|
}
|
|
|
|
|
|
- var task = await _unitOfWork.UserTaskAttachment.AddAsync(entity);
|
|
|
+ var attach = await _unitOfWork.UserTaskAttachment.AddAsync(entity);
|
|
|
await _unitOfWork.CompleteAsync();
|
|
|
|
|
|
- var response = MapperObject.Mapper.Map<AttachmentDto>(task);
|
|
|
-
|
|
|
+ var response = MapperObject.Mapper.Map<AttachmentDto>(attach);
|
|
|
+ var user = await _userService.GetUserNameEmail(attach.CreateUser);
|
|
|
+ response.ProfileImage = user.ProfileImage;
|
|
|
+ response.CreatedUserName = user.FullName;
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
|
|
|
public override async Task<AttachmentDto> Update(AttachmentDto input)
|
|
|
{
|
|
|
- var entitiy = await _unitOfWork.UserTaskAttachment.GetByIdAsync(input.Id);
|
|
|
+ var attach = await _unitOfWork.UserTaskAttachment.GetByIdAsync(input.Id);
|
|
|
|
|
|
- if (entitiy == null)
|
|
|
+ if (attach == null)
|
|
|
throw new AppException(ExceptionEnum.RecordNotExist);
|
|
|
|
|
|
- MapperObject.Mapper.Map(input, entitiy, typeof(AttachmentDto), typeof(UserTaskAttachment));
|
|
|
+ MapperObject.Mapper.Map(input, attach, typeof(AttachmentDto), typeof(UserTaskAttachment));
|
|
|
|
|
|
await _unitOfWork.CompleteAsync();
|
|
|
|
|
|
+ var response = MapperObject.Mapper.Map<AttachmentDto>(attach);
|
|
|
+
|
|
|
+ var user = await _userService.GetUserNameEmail(attach.CreateUser);
|
|
|
+ response.ProfileImage = user.ProfileImage;
|
|
|
+ response.CreatedUserName = user.FullName;
|
|
|
return input;
|
|
|
}
|
|
|
}
|