|
@@ -89,6 +89,81 @@ namespace MTWorkHR.Application.Services
|
|
|
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.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];
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ var attendance = await _unitOfWork.Attendance.GetAttendanceByUserId(id, DateTime.UtcNow.Date);
|
|
|
+ response.IsCheckedIn = attendance != null && attendance.CheckInTime.HasValue;
|
|
|
+ response.IsCheckedOut = attendance != null && attendance.CheckOutTime.HasValue;
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ public async Task<UserUpdateDto> GetByIdForUpdate(string id)
|
|
|
+ {
|
|
|
+ var entity = await _userManager.Users
|
|
|
+ .Include(x => x.UserRoles)
|
|
|
+ .Include(x => x.UserAddress).ThenInclude(x => x.City)
|
|
|
+ .Include(x => x.UserAddress).ThenInclude(x => x.Country)
|
|
|
+ .Include(x => x.UserAttachments)
|
|
|
+ .Include(x => x.JobTitle)
|
|
|
+ .Include(x => x.Industry)
|
|
|
+ .Include(x => x.University)
|
|
|
+ .Include(x => x.Country)
|
|
|
+ .Include(x => x.Qualification)
|
|
|
+ .FirstOrDefaultAsync(x => x.Id == id);
|
|
|
+ var response = MapperObject.Mapper.Map<UserUpdateDto>(entity);
|
|
|
+ if (response.UserAttachments != null)
|
|
|
+ foreach (var attach in response.UserAttachments)
|
|
|
+ {
|
|
|
switch (attach.AttachmentTypeId)
|
|
|
{
|
|
|
case 1:
|
|
@@ -101,20 +176,20 @@ namespace MTWorkHR.Application.Services
|
|
|
response.EduCertificateAttach = attach;
|
|
|
break;
|
|
|
case 4:
|
|
|
- response.ExperienceCertificateAttach= attach;
|
|
|
+ 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 6:
|
|
|
+ // response.CommercialRegAttach = file;
|
|
|
+ // break;
|
|
|
+ //case 7:
|
|
|
+ // response.TaxDeclarationAttach = file;
|
|
|
+ // break;
|
|
|
+ //case 8:
|
|
|
+ // response.IdAttach = file;
|
|
|
+ // break;
|
|
|
case 9:
|
|
|
response.ProfileImage = attach;
|
|
|
response.ProfileImagePath = attach.FilePath;
|
|
@@ -122,10 +197,7 @@ namespace MTWorkHR.Application.Services
|
|
|
}
|
|
|
attach.Content = new byte[0];
|
|
|
}
|
|
|
-
|
|
|
- var attendance = await _unitOfWork.Attendance.GetAttendanceByUserId(id, DateTime.UtcNow.Date);
|
|
|
- response.IsCheckedIn = attendance != null && attendance.CheckInTime.HasValue;
|
|
|
- response.IsCheckedOut = attendance != null && attendance.CheckOutTime.HasValue;
|
|
|
+
|
|
|
return response;
|
|
|
}
|
|
|
|
|
@@ -446,18 +518,36 @@ namespace MTWorkHR.Application.Services
|
|
|
//loop for given list of attachment, and move each file from Temp path to Actual path
|
|
|
// _fileService.UploadFiles(files);
|
|
|
input.CountryId = input.CountryId == null || input.CountryId == 0 ? input.UserAddress?.CountryId : input.CountryId;
|
|
|
- // 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);
|
|
|
-
|
|
|
+ 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 });
|
|
|
+ }
|
|
|
|
|
|
var files = input.UserAttachments.Select(a=> a.FileData).ToList();
|
|
|
List<AttachmentDto> attachs = input.UserAttachments.ToList();
|
|
|
+ if(attachs != null && attachs.Count > 0)
|
|
|
_fileService.CopyFileToCloud(ref attachs);
|
|
|
//if (!res)
|
|
|
// throw new AppException(ExceptionEnum.CouldNotMoveFiles);
|
|
@@ -550,19 +640,7 @@ namespace MTWorkHR.Application.Services
|
|
|
|
|
|
|
|
|
|
|
|
- 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)
|
|
|
{
|
|
|
var file = await _fileService.Download(filePath);
|
|
@@ -652,8 +730,8 @@ namespace MTWorkHR.Application.Services
|
|
|
throw e;
|
|
|
}
|
|
|
// Return updated user
|
|
|
- var userResponse = await GetById(input.Id);
|
|
|
- return MapperObject.Mapper.Map<UserUpdateDto>(userResponse);
|
|
|
+ var userResponse = await GetByIdForUpdate(input.Id);
|
|
|
+ return userResponse;
|
|
|
}
|
|
|
|
|
|
private void ProcessAttachment(ICollection<UserAttachment> oldAttachments, IList<AttachmentDto> newAttachments, AttachmentDto attachment,int attachmentTypeId)
|
|
@@ -670,7 +748,7 @@ namespace MTWorkHR.Application.Services
|
|
|
newAttachments.Add(new AttachmentDto
|
|
|
{
|
|
|
FilePath = attachment.FilePath,
|
|
|
- OriginalName = attachment.OriginalName,
|
|
|
+ OriginalName = string.IsNullOrEmpty( attachment.OriginalName) ? attachment.FileName : attachment.OriginalName,
|
|
|
FileName = attachment.FileName,
|
|
|
AttachmentTypeId = attachmentTypeId
|
|
|
});
|