|
@@ -27,6 +27,7 @@ using System.Linq;
|
|
using System.ComponentModel.Design;
|
|
using System.ComponentModel.Design;
|
|
using static iText.StyledXmlParser.Jsoup.Select.Evaluator;
|
|
using static iText.StyledXmlParser.Jsoup.Select.Evaluator;
|
|
using static iText.IO.Util.IntHashtable;
|
|
using static iText.IO.Util.IntHashtable;
|
|
|
|
+using Microsoft.Extensions.Logging;
|
|
|
|
|
|
namespace MTWorkHR.Application.Services
|
|
namespace MTWorkHR.Application.Services
|
|
{
|
|
{
|
|
@@ -41,10 +42,11 @@ namespace MTWorkHR.Application.Services
|
|
private readonly GlobalInfo _globalInfo;
|
|
private readonly GlobalInfo _globalInfo;
|
|
private readonly IFileService _fileService;
|
|
private readonly IFileService _fileService;
|
|
private readonly IOTPService _oTPService;
|
|
private readonly IOTPService _oTPService;
|
|
|
|
+ private readonly ILogger<UserService> _logger;
|
|
|
|
|
|
public UserService(ApplicationUserManager userManager, IUnitOfWork unitOfWork
|
|
public UserService(ApplicationUserManager userManager, IUnitOfWork unitOfWork
|
|
, RoleManager<ApplicationRole> roleManager, GlobalInfo globalInfo, AppSettingsConfiguration configuration, IMailSender emailSender
|
|
, RoleManager<ApplicationRole> roleManager, GlobalInfo globalInfo, AppSettingsConfiguration configuration, IMailSender emailSender
|
|
- , IUserRoleRepository<IdentityUserRole<string>> userRole, IFileService fileService, IOTPService oTPService)
|
|
|
|
|
|
+ , IUserRoleRepository<IdentityUserRole<string>> userRole, IFileService fileService, IOTPService oTPService, ILogger<UserService> logger)
|
|
{
|
|
{
|
|
_userManager = userManager;
|
|
_userManager = userManager;
|
|
_unitOfWork = unitOfWork;
|
|
_unitOfWork = unitOfWork;
|
|
@@ -55,6 +57,7 @@ namespace MTWorkHR.Application.Services
|
|
_globalInfo = globalInfo;
|
|
_globalInfo = globalInfo;
|
|
_fileService = fileService;
|
|
_fileService = fileService;
|
|
_oTPService = oTPService;
|
|
_oTPService = oTPService;
|
|
|
|
+ _logger = logger;
|
|
}
|
|
}
|
|
|
|
|
|
public async Task<UserDto> GetById()
|
|
public async Task<UserDto> GetById()
|
|
@@ -86,57 +89,38 @@ namespace MTWorkHR.Application.Services
|
|
if (response.UserAttachments != null)
|
|
if (response.UserAttachments != null)
|
|
foreach (var attach in response.UserAttachments.Where(a => a.Content != 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))
|
|
|
|
|
|
+ switch (attach.AttachmentTypeId)
|
|
{
|
|
{
|
|
- var file = new FormFile(stream, 0, stream.Length, Path.GetFileNameWithoutExtension(attach.FileName), attach.FilePath)
|
|
|
|
- {
|
|
|
|
- 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;
|
|
|
|
- case 3:
|
|
|
|
- response.EduCertificateAttach = file;
|
|
|
|
- break;
|
|
|
|
- case 4:
|
|
|
|
- response.ExperienceCertificateAttach= file;
|
|
|
|
- break;
|
|
|
|
- case 5:
|
|
|
|
- response.ProfCertificateAttach = file;
|
|
|
|
- break;
|
|
|
|
- case 6:
|
|
|
|
- response.CommercialRegAttach = file;
|
|
|
|
- break;
|
|
|
|
- case 7:
|
|
|
|
- response.TaxDeclarationAttach = file;
|
|
|
|
- break;
|
|
|
|
- case 8:
|
|
|
|
- response.IdAttach = file;
|
|
|
|
- break;
|
|
|
|
- case 9:
|
|
|
|
- response.ProfileImage = file;
|
|
|
|
- response.ProfileImagePath = attach.FilePath;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- attach.Content = new byte[0];
|
|
|
|
|
|
+ case 1:
|
|
|
|
+ response.CVAttach = attach;
|
|
|
|
+ break;
|
|
|
|
+ case 2:
|
|
|
|
+ response.PassportAttach = attach;
|
|
|
|
+ break;
|
|
|
|
+ case 3:
|
|
|
|
+ response.EduCertificateAttach = attach;
|
|
|
|
+ break;
|
|
|
|
+ case 4:
|
|
|
|
+ response.ExperienceCertificateAttach= attach;
|
|
|
|
+ break;
|
|
|
|
+ case 5:
|
|
|
|
+ response.ProfCertificateAttach = attach;
|
|
|
|
+ break;
|
|
|
|
+ case 6:
|
|
|
|
+ response.CommercialRegAttach = attach;
|
|
|
|
+ break;
|
|
|
|
+ case 7:
|
|
|
|
+ response.TaxDeclarationAttach = attach;
|
|
|
|
+ break;
|
|
|
|
+ case 8:
|
|
|
|
+ response.IdAttach = attach;
|
|
|
|
+ break;
|
|
|
|
+ case 9:
|
|
|
|
+ response.ProfileImage = attach;
|
|
|
|
+ response.ProfileImagePath = attach.FilePath;
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ attach.Content = new byte[0];
|
|
}
|
|
}
|
|
|
|
|
|
var attendance = await _unitOfWork.Attendance.GetAttendanceByUserId(id, DateTime.UtcNow.Date);
|
|
var attendance = await _unitOfWork.Attendance.GetAttendanceByUserId(id, DateTime.UtcNow.Date);
|
|
@@ -215,9 +199,23 @@ namespace MTWorkHR.Application.Services
|
|
public async Task<string> GetUserFullName(string userId)
|
|
public async Task<string> GetUserFullName(string userId)
|
|
{
|
|
{
|
|
var entity = await GetUserById(userId);
|
|
var entity = await GetUserById(userId);
|
|
- var name = entity == null ? "" : entity.FirstName + " " + entity.LastName;
|
|
|
|
|
|
+ var name = $"{entity.FirstName} {entity.LastName}".Trim();
|
|
return name;
|
|
return name;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public async Task<(string FullName, string Email)> GetUserNameEmail(string userId)
|
|
|
|
+ {
|
|
|
|
+ var entity = await GetUserById(userId);
|
|
|
|
+
|
|
|
|
+ if (entity == null)
|
|
|
|
+ return (string.Empty, string.Empty);
|
|
|
|
+
|
|
|
|
+ var name = $"{entity.FirstName} {entity.LastName}".Trim();
|
|
|
|
+ var email = entity.Email ?? string.Empty;
|
|
|
|
+
|
|
|
|
+ return (name, email);
|
|
|
|
+ }
|
|
|
|
+
|
|
public async Task<UserDto> GetUserWithAttachmentById(string id)
|
|
public async Task<UserDto> GetUserWithAttachmentById(string id)
|
|
{
|
|
{
|
|
var entity = await _userManager.Users.Include(u=> u.UserAttachments).Include(u=> u.JobTitle)
|
|
var entity = await _userManager.Users.Include(u=> u.UserAttachments).Include(u=> u.JobTitle)
|
|
@@ -448,32 +446,16 @@ namespace MTWorkHR.Application.Services
|
|
//loop for given list of attachment, and move each file from Temp path to Actual path
|
|
//loop for given list of attachment, and move each file from Temp path to Actual path
|
|
// _fileService.UploadFiles(files);
|
|
// _fileService.UploadFiles(files);
|
|
input.CountryId = input.CountryId == null || input.CountryId == 0 ? input.UserAddress?.CountryId : input.CountryId;
|
|
input.CountryId = input.CountryId == null || input.CountryId == 0 ? input.UserAddress?.CountryId : input.CountryId;
|
|
- if (input.UserAttachments == null )
|
|
|
|
- input.UserAttachments = new List<AttachmentDto>();
|
|
|
|
- if (input.ProfileImage != null)
|
|
|
|
- {
|
|
|
|
- input.UserAttachments.Add(new AttachmentDto { FileData = input.ProfileImage, OriginalName = input.ProfileImage?.Name, FileName = input.ProfileImage?.FileName, AttachmentTypeId = 9 });
|
|
|
|
- }
|
|
|
|
- if (input.CVAttach != null)
|
|
|
|
- {
|
|
|
|
- input.UserAttachments.Add(new AttachmentDto { FileData = input.CVAttach, OriginalName = input.CVAttach?.Name,FileName = input.CVAttach?.FileName, AttachmentTypeId = 1 });
|
|
|
|
- }
|
|
|
|
- if (input.PassportAttach != null)
|
|
|
|
- {
|
|
|
|
- input.UserAttachments.Add(new AttachmentDto { FileData = input.PassportAttach, OriginalName = input.PassportAttach?.Name, FileName = input.PassportAttach?.FileName, AttachmentTypeId = 2 });
|
|
|
|
- }
|
|
|
|
- if (input.EduCertificateAttach != null)
|
|
|
|
- {
|
|
|
|
- input.UserAttachments.Add(new AttachmentDto { FileData = input.EduCertificateAttach, OriginalName = input.EduCertificateAttach?.Name, FileName = input.EduCertificateAttach?.FileName, AttachmentTypeId = 3 });
|
|
|
|
- }
|
|
|
|
- if (input.ExperienceCertificateAttach != null)
|
|
|
|
- {
|
|
|
|
- input.UserAttachments.Add(new AttachmentDto { FileData = input.ExperienceCertificateAttach, OriginalName = input.ExperienceCertificateAttach?.Name, FileName = input.ExperienceCertificateAttach?.FileName, AttachmentTypeId = 4 });
|
|
|
|
- }
|
|
|
|
- if (input.ProfCertificateAttach != null)
|
|
|
|
- {
|
|
|
|
- input.UserAttachments.Add(new AttachmentDto { FileData = input.ProfCertificateAttach, OriginalName = input.ProfCertificateAttach?.Name, FileName = input.ProfCertificateAttach?.FileName, AttachmentTypeId = 5 });
|
|
|
|
- }
|
|
|
|
|
|
+ // if (input.UserAttachments == null )
|
|
|
|
+ input.UserAttachments = new List<AttachmentDto>();
|
|
|
|
+ AddAttachment(input.ProfileImage, 9, input.UserAttachments);
|
|
|
|
+ AddAttachment(input.CVAttach, 1, input.UserAttachments);
|
|
|
|
+ AddAttachment(input.PassportAttach, 2, input.UserAttachments);
|
|
|
|
+ AddAttachment(input.EduCertificateAttach, 3, input.UserAttachments);
|
|
|
|
+ AddAttachment(input.ExperienceCertificateAttach, 4, input.UserAttachments);
|
|
|
|
+ AddAttachment(input.ProfCertificateAttach, 5, input.UserAttachments);
|
|
|
|
+
|
|
|
|
+
|
|
var files = input.UserAttachments.Select(a=> a.FileData).ToList();
|
|
var files = input.UserAttachments.Select(a=> a.FileData).ToList();
|
|
List<AttachmentDto> attachs = input.UserAttachments.ToList();
|
|
List<AttachmentDto> attachs = input.UserAttachments.ToList();
|
|
_fileService.CopyFileToCloud(ref attachs);
|
|
_fileService.CopyFileToCloud(ref attachs);
|
|
@@ -535,7 +517,6 @@ namespace MTWorkHR.Application.Services
|
|
await _userManager.AddToRoleAsync(user, roleName);
|
|
await _userManager.AddToRoleAsync(user, roleName);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
// await _userRole.AddRangeAsync(userRoles);
|
|
// await _userRole.AddRangeAsync(userRoles);
|
|
|
|
|
|
await _unitOfWork.CompleteAsync();
|
|
await _unitOfWork.CompleteAsync();
|
|
@@ -555,17 +536,33 @@ namespace MTWorkHR.Application.Services
|
|
});
|
|
});
|
|
if (!sendMailResult)
|
|
if (!sendMailResult)
|
|
{
|
|
{
|
|
|
|
+ _logger.LogError("User created, but could not send the email!");
|
|
throw new AppException("User created, but could not send the email!");
|
|
throw new AppException("User created, but could not send the email!");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- catch
|
|
|
|
|
|
+ catch(Exception ex)
|
|
{
|
|
{
|
|
|
|
+ _logger.LogError(ex.Message);
|
|
throw new AppException("User created, but could not send the email!");
|
|
throw new AppException("User created, but could not send the email!");
|
|
}
|
|
}
|
|
-
|
|
|
|
return input;
|
|
return input;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private void AddAttachment(AttachmentDto attachment, int attachmentTypeId, IList<AttachmentDto> attachList)
|
|
|
|
+ {
|
|
|
|
+ if (attachment != null)
|
|
|
|
+ {
|
|
|
|
+ attachList.Add(new AttachmentDto
|
|
|
|
+ {
|
|
|
|
+ FilePath = attachment.FilePath,
|
|
|
|
+ OriginalName = attachment.OriginalName,
|
|
|
|
+ FileName = attachment.FileName,
|
|
|
|
+ AttachmentTypeId = attachmentTypeId
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
public async Task<BlobObject> Download(string filePath)
|
|
public async Task<BlobObject> Download(string filePath)
|
|
{
|
|
{
|
|
var file = await _fileService.Download(filePath);
|
|
var file = await _fileService.Download(filePath);
|
|
@@ -610,87 +607,43 @@ namespace MTWorkHR.Application.Services
|
|
var confirmEmailUrl = QueryHelpers.AddQueryString(userURL.ToString(), "token", codeHtmlVersion);
|
|
var confirmEmailUrl = QueryHelpers.AddQueryString(userURL.ToString(), "token", codeHtmlVersion);
|
|
return new Tuple<string, string>(confirmEmailUrl, user.Email);
|
|
return new Tuple<string, string>(confirmEmailUrl, user.Email);
|
|
}
|
|
}
|
|
-
|
|
|
|
public async Task<UserUpdateDto> Update(UserUpdateDto input)
|
|
public async Task<UserUpdateDto> Update(UserUpdateDto input)
|
|
{
|
|
{
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- var entity = _userManager.Users.Include(x => x.UserAttachments).FirstOrDefault(x=> x.Id == input.Id);
|
|
|
|
|
|
+ var entity = await _userManager.Users
|
|
|
|
+ .Include(x => x.UserAttachments)
|
|
|
|
+ .FirstOrDefaultAsync(x => x.Id == input.Id);
|
|
|
|
|
|
if (entity == null)
|
|
if (entity == null)
|
|
throw new AppException(ExceptionEnum.UserNotExist);
|
|
throw new AppException(ExceptionEnum.UserNotExist);
|
|
- if (input.UserAttachments == null)
|
|
|
|
- input.UserAttachments = new List<AttachmentDto>();
|
|
|
|
|
|
+
|
|
|
|
+ input.UserAttachments = new List<AttachmentDto>();
|
|
|
|
+
|
|
var oldAttachList = entity.UserAttachments;
|
|
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();
|
|
|
|
- _fileService.CopyFileToCloud(ref attachs);
|
|
|
|
- input.UserAttachments = attachs;
|
|
|
|
|
|
|
|
- //if (!await _fileService.CopyFileToActualFolder(input.UserAttachments.ToList()))
|
|
|
|
- // throw new AppException(ExceptionEnum.CouldNotMoveFiles);
|
|
|
|
|
|
+ // Process each attachment type
|
|
|
|
+ ProcessAttachment(oldAttachList, input.UserAttachments, input.ProfileImage, 9);
|
|
|
|
+ ProcessAttachment(oldAttachList, input.UserAttachments, input.CVAttach, 1);
|
|
|
|
+ ProcessAttachment(oldAttachList, input.UserAttachments, input.PassportAttach, 2);
|
|
|
|
+ ProcessAttachment(oldAttachList, input.UserAttachments, input.EduCertificateAttach, 3);
|
|
|
|
+ ProcessAttachment(oldAttachList, input.UserAttachments, input.ExperienceCertificateAttach, 4);
|
|
|
|
+ ProcessAttachment(oldAttachList, input.UserAttachments, input.ProfCertificateAttach, 5);
|
|
|
|
|
|
|
|
+ // Cloud copy
|
|
|
|
+ List<AttachmentDto> attachments = input.UserAttachments.ToList();
|
|
|
|
+ _fileService.CopyFileToCloud(ref attachments);
|
|
|
|
+ input.UserAttachments = attachments;
|
|
|
|
|
|
|
|
+ // Map updated input to entity
|
|
MapperObject.Mapper.Map(input, entity);
|
|
MapperObject.Mapper.Map(input, entity);
|
|
|
|
+ entity.UpdateDate = DateTime.UtcNow;
|
|
|
|
|
|
_unitOfWork.BeginTran();
|
|
_unitOfWork.BeginTran();
|
|
- entity.UpdateDate = DateTime.UtcNow;
|
|
|
|
- //saving user
|
|
|
|
var result = await _userManager.UpdateAsync(entity);
|
|
var result = await _userManager.UpdateAsync(entity);
|
|
if (!result.Succeeded)
|
|
if (!result.Succeeded)
|
|
throw new AppException(ExceptionEnum.RecordUpdateFailed);
|
|
throw new AppException(ExceptionEnum.RecordUpdateFailed);
|
|
|
|
|
|
- //**saving userRoles
|
|
|
|
-
|
|
|
|
- //add new user roles
|
|
|
|
- //var exsitedRolesIds = await _userRole.GetUserRoleIdsByUserID(input.Id);
|
|
|
|
- //if (input.UserRoles == null)
|
|
|
|
- // input.UserRoles = new List<UserRoleDto>();
|
|
|
|
- //var newAddedRoles = MapperObject.Mapper.Map<List<IdentityUserRole<string>>>(input.UserRoles.Where(x => !exsitedRolesIds.Contains(x.RoleId)));
|
|
|
|
- //newAddedRoles.ForEach(x => x.UserId = input.Id);
|
|
|
|
- //await _userRole.AddRangeAsync(newAddedRoles);
|
|
|
|
-
|
|
|
|
- ////delete removed roles
|
|
|
|
- //var rolesIds = input.UserRoles.Select(x => x.RoleId).ToArray();
|
|
|
|
- //var removedRoles = await _userRole.GetRemovedUserRoleIdsByUserID(input.Id, rolesIds);
|
|
|
|
- //await _userRole.DeleteAsync(removedRoles.AsEnumerable());
|
|
|
|
-
|
|
|
|
-
|
|
|
|
await _unitOfWork.CompleteAsync();
|
|
await _unitOfWork.CompleteAsync();
|
|
_unitOfWork.CommitTran();
|
|
_unitOfWork.CommitTran();
|
|
}
|
|
}
|
|
@@ -698,11 +651,109 @@ namespace MTWorkHR.Application.Services
|
|
{
|
|
{
|
|
throw e;
|
|
throw e;
|
|
}
|
|
}
|
|
|
|
+ // Return updated user
|
|
var userResponse = await GetById(input.Id);
|
|
var userResponse = await GetById(input.Id);
|
|
- var user = MapperObject.Mapper.Map<UserUpdateDto>(userResponse);
|
|
|
|
- return user;
|
|
|
|
|
|
+ return MapperObject.Mapper.Map<UserUpdateDto>(userResponse);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void ProcessAttachment(ICollection<UserAttachment> oldAttachments, IList<AttachmentDto> newAttachments, AttachmentDto attachment,int attachmentTypeId)
|
|
|
|
+ {
|
|
|
|
+ if (attachment == null)
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ var oldAttach = oldAttachments
|
|
|
|
+ .FirstOrDefault(x => x.AttachmentTypeId == attachmentTypeId || x.FileName == attachment.FileName);
|
|
|
|
+
|
|
|
|
+ if (oldAttach != null)
|
|
|
|
+ oldAttachments.Remove(oldAttach);
|
|
|
|
+
|
|
|
|
+ newAttachments.Add(new AttachmentDto
|
|
|
|
+ {
|
|
|
|
+ FilePath = attachment.FilePath,
|
|
|
|
+ OriginalName = attachment.OriginalName,
|
|
|
|
+ FileName = attachment.FileName,
|
|
|
|
+ AttachmentTypeId = attachmentTypeId
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //public async Task<UserUpdateDto> Update2(UserUpdateDto input)
|
|
|
|
+ //{
|
|
|
|
+ // try
|
|
|
|
+ // {
|
|
|
|
+ // var entity = _userManager.Users.Include(x => x.UserAttachments).FirstOrDefault(x=> x.Id == input.Id);
|
|
|
|
+
|
|
|
|
+ // if (entity == null)
|
|
|
|
+ // throw new AppException(ExceptionEnum.UserNotExist);
|
|
|
|
+ // 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();
|
|
|
|
+ // _fileService.CopyFileToCloud(ref attachs);
|
|
|
|
+ // input.UserAttachments = attachs;
|
|
|
|
+
|
|
|
|
+ // //if (!await _fileService.CopyFileToActualFolder(input.UserAttachments.ToList()))
|
|
|
|
+ // // throw new AppException(ExceptionEnum.CouldNotMoveFiles);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // MapperObject.Mapper.Map(input, entity);
|
|
|
|
+
|
|
|
|
+ // _unitOfWork.BeginTran();
|
|
|
|
+ // entity.UpdateDate = DateTime.UtcNow;
|
|
|
|
+ // //saving user
|
|
|
|
+ // var result = await _userManager.UpdateAsync(entity);
|
|
|
|
+ // if (!result.Succeeded)
|
|
|
|
+ // throw new AppException(ExceptionEnum.RecordUpdateFailed);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // await _unitOfWork.CompleteAsync();
|
|
|
|
+ // _unitOfWork.CommitTran();
|
|
|
|
+ // }
|
|
|
|
+ // catch (Exception e)
|
|
|
|
+ // {
|
|
|
|
+ // throw e;
|
|
|
|
+ // }
|
|
|
|
+ // var userResponse = await GetById(input.Id);
|
|
|
|
+ // var user = MapperObject.Mapper.Map<UserUpdateDto>(userResponse);
|
|
|
|
+ // return user;
|
|
|
|
+ //}
|
|
|
|
+
|
|
public async Task<bool> Update(string userId, long companyId)
|
|
public async Task<bool> Update(string userId, long companyId)
|
|
{
|
|
{
|
|
try
|
|
try
|