|
@@ -58,20 +58,35 @@ namespace MTWorkHR.Application.Services
|
|
|
|
|
|
public override async Task<CompanyDto> Create(CompanyDto input)
|
|
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);
|
|
var entity = MapperObject.Mapper.Map<Company>(input);
|
|
if (entity is null)
|
|
if (entity is null)
|
|
{
|
|
{
|
|
throw new AppException(ExceptionEnum.MapperIssue);
|
|
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();
|
|
await _unitOfWork.CompleteAsync();
|
|
|
|
|
|
- var response = MapperObject.Mapper.Map<CompanyDto>(task);
|
|
|
|
|
|
+ var response = MapperObject.Mapper.Map<CompanyDto>(company);
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
- public async Task<string> CreateCompanyUser(CompanyDto input)
|
|
|
|
|
|
+ public async Task<ApplicationUser> CreateCompanyUser(CompanyDto input)
|
|
{
|
|
{
|
|
var companyUser = MapperObject.Mapper.Map<UserDto>(input.CompanyUser);
|
|
var companyUser = MapperObject.Mapper.Map<UserDto>(input.CompanyUser);
|
|
|
|
|
|
@@ -130,7 +145,7 @@ namespace MTWorkHR.Application.Services
|
|
}
|
|
}
|
|
throw new AppException(ExceptionEnum.RecordCreationFailed);
|
|
throw new AppException(ExceptionEnum.RecordCreationFailed);
|
|
}
|
|
}
|
|
- return user.Id;
|
|
|
|
|
|
+ return user;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|