public async Task <ExecutionResult> CreateCompanyUser(CompanyUserEntity companyUser) { var collection = this.mongoDataProvider.CompanyDb.GetCollection <CompanyUserEntity>(CompanyUserCollection); var c = await collection.CountAsync(x => x.UserIdentifier == companyUser.UserIdentifier && x.CompanyIdentifier == companyUser.CompanyIdentifier); if (c > 0) { return(new ExecutionResult <CompanyUserEntity>(ErrorInfoFacory.CreateOne("The user already exist"))); } await collection.InsertOneAsync(companyUser); return(new ExecutionResult()); }
public async Task <IActionResult> Register([FromBody] RegisterModel model) { var principalInfo = User.GetInfo(); byte[] salt = new byte[128]; using (var rng = RandomNumberGenerator.Create()) { rng.GetBytes(salt); } CompanyUserEntity companyUser = new CompanyUserEntity() { CompanyIdentifier = model.CompanyIdentifier, IsDefault = true, PasswordHash = GetHashString(model.Password, salt), UserIdentifier = principalInfo.Login }; await this.companyUserService.CreateCompanyUser(companyUser); return(Ok(new ApiResponse())); }