|
@@ -137,8 +137,9 @@ namespace MTWorkHR.Application.Services
|
|
public override async Task<CompanyDto> Update(CompanyDto input)
|
|
public override async Task<CompanyDto> Update(CompanyDto input)
|
|
{
|
|
{
|
|
var companyUser = MapperObject.Mapper.Map<UserUpdateDto>(input.CompanyUser);
|
|
var companyUser = MapperObject.Mapper.Map<UserUpdateDto>(input.CompanyUser);
|
|
|
|
+ _unitOfWork.BeginTran();
|
|
|
|
|
|
- await _userService.Update(companyUser);
|
|
|
|
|
|
+ await UpdateCompanyUser(input);
|
|
var entity = await _unitOfWork.Company.GetByIdAsync(input.Id);
|
|
var entity = await _unitOfWork.Company.GetByIdAsync(input.Id);
|
|
|
|
|
|
if (entity == null)
|
|
if (entity == null)
|
|
@@ -147,10 +148,84 @@ namespace MTWorkHR.Application.Services
|
|
MapperObject.Mapper.Map(input, entity, typeof(CompanyDto), typeof(Company));
|
|
MapperObject.Mapper.Map(input, entity, typeof(CompanyDto), typeof(Company));
|
|
|
|
|
|
await _unitOfWork.CompleteAsync();
|
|
await _unitOfWork.CompleteAsync();
|
|
|
|
+ _unitOfWork.CommitTran();
|
|
|
|
|
|
return input;
|
|
return input;
|
|
}
|
|
}
|
|
|
|
+ public async Task<UserUpdateDto> UpdateCompanyUser(CompanyDto input)
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ var entity = _userManager.Users.Include(x => x.UserAttachments).FirstOrDefault(x => x.Id == input.UserId);
|
|
|
|
+
|
|
|
|
+ if (entity == null)
|
|
|
|
+ throw new AppException(ExceptionEnum.RecordNotExist);
|
|
|
|
+ if (input.CompanyUser != null && input.CompanyUser.UserAttachments == null)
|
|
|
|
+ input.CompanyUser.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.CompanyUser?.UserAttachments.Add(new AttachmentDto { FileData = input.ProfileImage, OriginalName = input.ProfileImage?.Name, FileName = input.ProfileImage?.FileName, AttachmentTypeId = 9 });
|
|
|
|
+ }
|
|
|
|
+ if (input.CommercialRegAttach != null)
|
|
|
|
+ {
|
|
|
|
+ var oldAttach = oldAttachList.Where(x => x.AttachmentTypeId == 1 || x.OriginalName == input.CommercialRegAttach?.Name).FirstOrDefault();
|
|
|
|
+ if (oldAttach != null) entity.UserAttachments.Remove(oldAttach);
|
|
|
|
+ input.CompanyUser?.UserAttachments.Add(new AttachmentDto { FileData = input.CommercialRegAttach, OriginalName = input.CommercialRegAttach?.Name, FileName = input.CommercialRegAttach?.FileName, AttachmentTypeId = 6 });
|
|
|
|
+ }
|
|
|
|
+ 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.CompanyUser?.UserAttachments.Add(new AttachmentDto { FileData = input.PassportAttach, OriginalName = input.PassportAttach?.Name, FileName = input.PassportAttach?.FileName, AttachmentTypeId = 2 });
|
|
|
|
+ }
|
|
|
|
+ if (input.TaxDeclarationAttach != null)
|
|
|
|
+ {
|
|
|
|
+ var oldAttach = oldAttachList.Where(x => x.AttachmentTypeId == 3 || x.OriginalName == input.TaxDeclarationAttach?.Name).FirstOrDefault();
|
|
|
|
+ if (oldAttach != null) entity.UserAttachments.Remove(oldAttach);
|
|
|
|
+ input.CompanyUser?.UserAttachments.Add(new AttachmentDto { FileData = input.TaxDeclarationAttach, OriginalName = input.TaxDeclarationAttach?.Name, FileName = input.TaxDeclarationAttach?.FileName, AttachmentTypeId = 7});
|
|
|
|
+ }
|
|
|
|
+ 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.CompanyUser?.UserAttachments.Add(new AttachmentDto { FileData = input.ExperienceCertificateAttach, OriginalName = input.ExperienceCertificateAttach?.Name, FileName = input.ExperienceCertificateAttach?.FileName, AttachmentTypeId = 4 });
|
|
|
|
+ }
|
|
|
|
+ if (input.IdAttach != null)
|
|
|
|
+ {
|
|
|
|
+ var oldAttach = oldAttachList.Where(x => x.AttachmentTypeId == 5 || x.OriginalName == input.IdAttach?.Name).FirstOrDefault();
|
|
|
|
+ if (oldAttach != null) entity.UserAttachments.Remove(oldAttach);
|
|
|
|
+ input.CompanyUser?.UserAttachments.Add(new AttachmentDto { FileData = input.IdAttach, OriginalName = input.IdAttach?.Name, FileName = input.IdAttach?.FileName, AttachmentTypeId = 8 });
|
|
|
|
+ }
|
|
|
|
+ List<AttachmentDto> attachs = input.CompanyUser?.UserAttachments.ToList();
|
|
|
|
+ _fileService.CopyFileToCloud(ref attachs);
|
|
|
|
+ input.CompanyUser.UserAttachments = attachs;
|
|
|
|
+
|
|
|
|
+ //if (!await _fileService.CopyFileToActualFolder(input.UserAttachments.ToList()))
|
|
|
|
+ // throw new AppException(ExceptionEnum.CouldNotMoveFiles);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ MapperObject.Mapper.Map(input.CompanyUser, entity);
|
|
|
|
|
|
|
|
+
|
|
|
|
+ //saving user
|
|
|
|
+ var result = await _userManager.UpdateAsync(entity);
|
|
|
|
+ if (!result.Succeeded)
|
|
|
|
+ throw new AppException(ExceptionEnum.RecordUpdateFailed);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ await _unitOfWork.CompleteAsync();
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e)
|
|
|
|
+ {
|
|
|
|
+ throw e;
|
|
|
|
+ }
|
|
|
|
+ var userResponse = await GetById(input.Id);
|
|
|
|
+ var user = MapperObject.Mapper.Map<UserUpdateDto>(userResponse);
|
|
|
|
+ return user;
|
|
|
|
+ }
|
|
|
|
|
|
public override async Task Delete(long id)
|
|
public override async Task Delete(long id)
|
|
{
|
|
{
|