zinab_elgendy месяцев назад: 6
Родитель
Сommit
acd9cff971

+ 1 - 1
MTWorkHR.API/Program.cs

@@ -19,7 +19,7 @@ var builder = WebApplication.CreateBuilder(args);
 var config = new AppSettingsConfiguration();
 // Add services to the container.
 builder.Services.AddDbContext<HRDataContext>(options =>
-{   
+{
     options.UseSqlServer(config.ConnectionStrings.LocalConnectionString);
   //  options.UseSqlServer(builder.Configuration.GetSection("ConnectionStrings:MTWorkHRConnectionString").Value);
 });

+ 1 - 1
MTWorkHR.API/appsettings.json

@@ -39,7 +39,7 @@
     "TemplatePath": "C:\\Attachment\\MailTemp\\EmailTemplate.html"
   },
   "OTPSettings": {
-    "Length": 6,
+    "Length": 4,
     "ExpirePeriodInMinutes": 3000,
     "SendEmail": true,
     "AllowZeros": true,

+ 76 - 1
MTWorkHR.Application/Services/User/CompanyService.cs

@@ -137,8 +137,9 @@ namespace MTWorkHR.Application.Services
         public override async Task<CompanyDto> Update(CompanyDto input)
         {
             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);
 
             if (entity == null)
@@ -147,10 +148,84 @@ namespace MTWorkHR.Application.Services
             MapperObject.Mapper.Map(input, entity, typeof(CompanyDto), typeof(Company));
 
             await _unitOfWork.CompleteAsync();
+            _unitOfWork.CommitTran();
 
             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)
         {

+ 1 - 3
MTWorkHR.Application/Services/User/UserService.cs

@@ -473,9 +473,7 @@ namespace MTWorkHR.Application.Services
             var user = MapperObject.Mapper.Map<UserUpdateDto>(userResponse);
             return user;
         }
-
-
-       
+        
 
         public async Task<bool> IsExpiredToken(ConfirmEmailDto input)
         {