|
@@ -21,6 +21,8 @@ using System.Linq.Dynamic.Core;
|
|
|
using MTWorkHR.Core.Entities.Base;
|
|
|
using MTWorkHR.Infrastructure.EmailService;
|
|
|
using Countries.NET.Database;
|
|
|
+using Microsoft.AspNetCore.Http;
|
|
|
+using System.Collections;
|
|
|
|
|
|
namespace MTWorkHR.Application.Services
|
|
|
{
|
|
@@ -66,7 +68,37 @@ namespace MTWorkHR.Application.Services
|
|
|
.Include(x => x.Qualification)
|
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
|
var response = MapperObject.Mapper.Map<UserDto>(entity);
|
|
|
-
|
|
|
+ if (response.UserAttachments != null)
|
|
|
+ foreach (var attach in response.UserAttachments.Where(a => a.Content != null))
|
|
|
+ {
|
|
|
+ //var stream = new MemoryStream(attach.Content);
|
|
|
+ //IFormFile file = new FormFile(stream, 0, stream.Length, Path.GetFileNameWithoutExtension(attach.FileName), attach.FileName);
|
|
|
+
|
|
|
+ using (var stream = new MemoryStream(attach.Content))
|
|
|
+ {
|
|
|
+ var file = new FormFile(stream, 0, stream.Length, Path.GetFileNameWithoutExtension(attach.FileName), attach.FileName)
|
|
|
+ {
|
|
|
+ Headers = new HeaderDictionary(),
|
|
|
+ ContentType = attach.ContentType,
|
|
|
+ };
|
|
|
+
|
|
|
+ System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition
|
|
|
+ {
|
|
|
+ FileName = file.FileName
|
|
|
+ };
|
|
|
+ file.ContentDisposition = cd.ToString();
|
|
|
+ switch (attach.AttachmentTypeId)
|
|
|
+ {
|
|
|
+ case 1:
|
|
|
+ response.CVAttach = file;
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ response.PassportAttach = file;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
return response;
|
|
|
}
|
|
|
public async Task<UserDto> GetUserById(string id)
|
|
@@ -304,6 +336,12 @@ namespace MTWorkHR.Application.Services
|
|
|
|
|
|
return input;
|
|
|
}
|
|
|
+
|
|
|
+ public async Task<BlobObject> Download(string filePath)
|
|
|
+ {
|
|
|
+ var file = await _fileService.Download(filePath);
|
|
|
+ return file;
|
|
|
+ }
|
|
|
public async Task<bool> ConfirmEmail(ConfirmEmailDto input)
|
|
|
{
|
|
|
var user = await _userManager.FindByIdAsync(input.UserId);
|
|
@@ -348,34 +386,47 @@ namespace MTWorkHR.Application.Services
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- var entity = await _userManager.FindByIdAsync(input.Id);
|
|
|
+ var entity = _userManager.Users.Include(x => x.UserAttachments).FirstOrDefault(x=> x.Id == input.Id);
|
|
|
|
|
|
if (entity == null)
|
|
|
throw new AppException(ExceptionEnum.RecordNotExist);
|
|
|
if (input.UserAttachments == null)
|
|
|
input.UserAttachments = new List<AttachmentDto>();
|
|
|
+ var oldAttachList = entity.UserAttachments;
|
|
|
if (input.ProfileImage != null)
|
|
|
{
|
|
|
+ var oldAttach = oldAttachList.Where(x => x.AttachmentTypeId == 9 || x.OriginalName == input.ProfileImage?.Name).FirstOrDefault();
|
|
|
+ if(oldAttach != null) entity.UserAttachments.Remove(oldAttach);
|
|
|
input.UserAttachments.Add(new AttachmentDto { FileData = input.ProfileImage, OriginalName = input.ProfileImage?.Name, FileName = input.ProfileImage?.FileName, AttachmentTypeId = 9 });
|
|
|
}
|
|
|
if (input.CVAttach != null)
|
|
|
{
|
|
|
+ var oldAttach = oldAttachList.Where(x => x.AttachmentTypeId == 1 || x.OriginalName == input.CVAttach?.Name).FirstOrDefault();
|
|
|
+ if (oldAttach != null) entity.UserAttachments.Remove(oldAttach);
|
|
|
input.UserAttachments.Add(new AttachmentDto { FileData = input.CVAttach, OriginalName = input.CVAttach?.Name, FileName = input.CVAttach?.FileName, AttachmentTypeId = 1 });
|
|
|
}
|
|
|
if (input.PassportAttach != null)
|
|
|
{
|
|
|
+ var oldAttach = oldAttachList.Where(x => x.AttachmentTypeId == 2 || x.OriginalName == input.PassportAttach?.Name).FirstOrDefault();
|
|
|
+ if (oldAttach != null) entity.UserAttachments.Remove(oldAttach);
|
|
|
input.UserAttachments.Add(new AttachmentDto { FileData = input.PassportAttach, OriginalName = input.PassportAttach?.Name, FileName = input.PassportAttach?.FileName, AttachmentTypeId = 2 });
|
|
|
}
|
|
|
if (input.EduCertificateAttach != null)
|
|
|
{
|
|
|
+ var oldAttach = oldAttachList.Where(x => x.AttachmentTypeId == 3 || x.OriginalName == input.EduCertificateAttach?.Name).FirstOrDefault();
|
|
|
+ if (oldAttach != null) entity.UserAttachments.Remove(oldAttach);
|
|
|
input.UserAttachments.Add(new AttachmentDto { FileData = input.EduCertificateAttach, OriginalName = input.EduCertificateAttach?.Name, FileName = input.EduCertificateAttach?.FileName, AttachmentTypeId = 3 });
|
|
|
}
|
|
|
if (input.ExperienceCertificateAttach != null)
|
|
|
{
|
|
|
+ var oldAttach = oldAttachList.Where(x => x.AttachmentTypeId == 4 || x.OriginalName == input.ExperienceCertificateAttach?.Name).FirstOrDefault();
|
|
|
+ if (oldAttach != null) entity.UserAttachments.Remove(oldAttach);
|
|
|
input.UserAttachments.Add(new AttachmentDto { FileData = input.ExperienceCertificateAttach, OriginalName = input.ExperienceCertificateAttach?.Name, FileName = input.ExperienceCertificateAttach?.FileName, AttachmentTypeId = 4 });
|
|
|
}
|
|
|
if (input.ProfCertificateAttach != null)
|
|
|
{
|
|
|
+ var oldAttach = oldAttachList.Where(x => x.AttachmentTypeId == 5 || x.OriginalName == input.ProfCertificateAttach?.Name).FirstOrDefault();
|
|
|
+ if (oldAttach != null) entity.UserAttachments.Remove(oldAttach);
|
|
|
input.UserAttachments.Add(new AttachmentDto { FileData = input.ProfCertificateAttach, OriginalName = input.ProfCertificateAttach?.Name, FileName = input.ProfCertificateAttach?.FileName, AttachmentTypeId = 5 });
|
|
|
}
|
|
|
List<AttachmentDto> attachs = input.UserAttachments.ToList();
|
|
@@ -418,8 +469,9 @@ namespace MTWorkHR.Application.Services
|
|
|
{
|
|
|
throw e;
|
|
|
}
|
|
|
-
|
|
|
- return input;
|
|
|
+ var userResponse = await GetById(input.Id);
|
|
|
+ var user = MapperObject.Mapper.Map<UserUpdateDto>(userResponse);
|
|
|
+ return user;
|
|
|
}
|
|
|
|
|
|
|