public async Task <ActionResult <AgentAccountDto> > CreateAgent([FromBody] AgentAccountDto dto, CancellationToken cancellationToken) { if (_userProvider.RealEstateId is null) { throw new AppException("you cannot create new agent please try again later"); } var dupUser = await _userAccountService.GetAsync(u => u.Email == dto.Email || u.UserName == dto.UserName, cancellationToken); if (dupUser != null) { if (dupUser.Email == dto.Email) { throw new AppException("There is another user registered with this email address. Please chose another one."); } if (dupUser.UserName == dto.UserName) { throw new AppException("There is another user registered with this username. Please chose another one."); } } var passwordHash = _passwordService.HashUserPassword(dto.Email, dto.Password); var user = await _userAccountService.CreateAsync(new UserAccount { ActivationKey = _fastHasher.CalculateHash(dto.FirstName + dto.LastName + dto.Email + dto.UserName), Email = dto.Email, UserName = dto.UserName, FirstName = dto.FirstName, LastName = dto.LastName, HasExternalAuthentication = false, IsConfirmed = false, PasswordHash = passwordHash, RegistrationDate = DateTime.Now, Address01 = dto.Address01, Address02 = dto.Address02, Phone01 = dto.Phone01, Phone02 = dto.Phone02, IsActive = true, MiddleName = dto.MiddleName, ReferralCode = _fastHasher.CalculateTimeHash(dto.Email), ZipCode = dto.ZipCode, }, cancellationToken); dto.UserId = user.Id; var agent = await ModelService.CreateAsync(new Agent { Description = dto.Description, HasPublishingAuthorization = dto.HasPublishingAuthorization, IsResponsible = dto.IsResponsible, RealEstateId = _userProvider.RealEstateId.Value, MetadataJson = "{}", UserAccountId = user.Id, }, cancellationToken); dto.AgentId = agent.Id; return(CreatedAtAction(nameof(CreateAgent), dto)); }
public virtual async Task CreateAsync() { var model = await ModelService.CreateAsync(ConstructElement()); AddModelToCollection(model); }