public async Task <Guid> Handle(RegisterNewUserAccountCommand command, CancellationToken cancellationToken = default(CancellationToken)) { await ValidateForUniqueness(command); var sponsorId = await GetSponsorId(command); var hashSalt = PasswordEncryptionUtilities.GenerateSaltedHash(command.Password); var userAccountData = new UserAccountData ( id: Guid.NewGuid(), email: command.Email, login: command.Login, firstName: command.FirstName, lastName: command.LastName, street: command.Street, city: command.City, zipCode: command.ZipCode, country: command.Country, btcWalletAddress: command.BtcWalletAddress, role: UserRolesHelper.User ); userAccountData.SetPassword(hashSalt.Salt, hashSalt.Hash); await _context.Set <UserAccountData>().AddAsync(userAccountData); await _context.SaveChangesAsync(); // TODO: Event that user was created: eventhandler should create new multiaccount for him var userMultiAccount = new UserMultiAccount ( id: Guid.NewGuid(), userAccountDataId: userAccountData.Id, sponsorId: sponsorId, multiAccountName: userAccountData.Login ); userMultiAccount.SetAsMainAccount(); await _userMultiAccountRepository.CreateAsync(userMultiAccount); return(userAccountData.Id); }
public async Task <Guid> Handle(CreateMultiAccountCommand command, CancellationToken cancellationToken = default(CancellationToken)) { _command = command; await ValidateIfMultiAccountCanBeCreated(); var sponsor = await GetSponsor(); var multiAccountName = await _userMultiAccountHelper.GenerateNextMultiAccountName(_command.UserAccountId); var userMultiAccount = new UserMultiAccount ( id: Guid.NewGuid(), userAccountDataId: _command.UserAccountId, sponsorId: sponsor.Id, multiAccountName: multiAccountName ); await _userMultiAccountRepository.CreateAsync(userMultiAccount); return(userMultiAccount.Id); }