Bläddra i källkod

userCompany save companyId

zinab_elgendy 6 månader sedan
förälder
incheckning
f91e280668

+ 2 - 2
MTWorkHR.Application/ApplicationServiceRegistration.cs

@@ -22,8 +22,8 @@ namespace MTWorkHR.Application
 
             services.AddTransient<IAuthService, AuthService>();
             services.AddTransient<IUserService, UserService>();
-            services.AddTransient<IFileService, FileService>();
-            //services.AddTransient<IFileService, BlobFileService>();
+           // services.AddTransient<IFileService, FileService>();
+            services.AddTransient<IFileService, BlobFileService>();
             services.AddScoped<IProjectService, ProjectService>();
             services.AddScoped<IUserTaskService, UserTaskService>();
             services.AddScoped<IUserTaskAttachmentService, UserTaskAttachmentService>();

+ 20 - 5
MTWorkHR.Application/Services/User/CompanyService.cs

@@ -58,20 +58,35 @@ namespace MTWorkHR.Application.Services
 
         public override async Task<CompanyDto> Create(CompanyDto input)
         {
-            input.UserId = await CreateCompanyUser(input);
+            if(input.CompanyUser != null)
+            {
+                var emailExists = await _userManager.FindByEmailAsync(input.CompanyUser.Email);
+                if (emailExists != null)
+                    throw new AppException(ExceptionEnum.RecordAlreadyExist);
+
+                var phoneExists = await _userManager.FindByAnyAsync(input.CompanyUser.PhoneNumber);
+                if (phoneExists != null)
+                    throw new AppException(ExceptionEnum.RecordAlreadyExist);
+
+            }
+
+            var UserCreated = await CreateCompanyUser(input);
+            input.UserId = UserCreated.Id;
             var entity = MapperObject.Mapper.Map<Company>(input);
             if (entity is null)
             {
                 throw new AppException(ExceptionEnum.MapperIssue);
             }
 
-            var task = await _unitOfWork.Company.AddAsync(entity);
+            var company = await _unitOfWork.Company.AddAsync(entity);
+
+            UserCreated.CompanyId = company.Id;
             await _unitOfWork.CompleteAsync();
 
-            var response = MapperObject.Mapper.Map<CompanyDto>(task);
+            var response = MapperObject.Mapper.Map<CompanyDto>(company);
             return response;
         }
-        public async Task<string> CreateCompanyUser(CompanyDto input)
+        public async Task<ApplicationUser> CreateCompanyUser(CompanyDto input)
         {
             var companyUser = MapperObject.Mapper.Map<UserDto>(input.CompanyUser);
 
@@ -130,7 +145,7 @@ namespace MTWorkHR.Application.Services
                 }
                 throw new AppException(ExceptionEnum.RecordCreationFailed);
             }
-            return user.Id;
+            return user;
         }