private async Task <Guid> GetSponsorByReflink(string reflink)
        {
            var sponsor = await _userMultiAccountRepository.GetByReflinkAsync(reflink);

            if (sponsor is null)
            {
                throw new InvalidOperationException("User with given reflink does not exist");
            }

            return(sponsor.Id);
        }
Пример #2
0
        private async Task ValidateIfMultiAccountCanBeCreated()
        {
            var userAccount = await _userAccountDataRepository.GetAsync(_command.UserAccountId);

            if (userAccount is null)
            {
                throw new AccountNotFoundException("User with given ID does not exist");
            }

            var sponsor = await _userMultiAccountRepository.GetByReflinkAsync(_command.SponsorReflink);

            if (sponsor is null)
            {
                throw new AccountNotFoundException("Account with given reflink does not exist");
            }

            if (CheckIfReflinkBelongsToRequestedUser(sponsor))
            {
                throw new ValidationException("Given reflink belongs to the requested user account");
            }


            if (!userAccount.IsMembershipFeePaid)
            {
                throw new ValidationException("The main account did not pay the membership's fee yet");
            }

            var userMultiAccountIds = userAccount.UserMultiAccounts.Select(x => x.Id).ToList();

            if (!await CheckIfAllMultiAccountsAreInMatrixPositions(userMultiAccountIds))
            {
                throw new ValidationException("Not all user multi accounts are available in matrix positions");
            }

            if (userAccount.UserMultiAccounts.Count > 20)
            {
                throw new ValidationException("You cannot have more than 20 multi accounts attached to the main account");
            }
        }