Exemple #1
0
 public Wallet(string uniqueMasterCitizenNumberValue,
               SupportedBank supportedBank,
               string firstName,
               string lastName,
               string password,
               string postalIndexNumber)
 {
     UniqueMasterCitizenNumber = new UniqueMasterCitizenNumber(uniqueMasterCitizenNumberValue);
     PersonalData        = new PersonalData(firstName, lastName);
     SupportedBank       = supportedBank;
     Password            = password;
     PostalIndexNumber   = postalIndexNumber;
     Status              = WalletStatus.ACTIVE;
     CreatedAt           = DateTime.Now;
     PaymentTransactions = new List <PaymentTransaction>();
 }
        public async Task <WalletDTO> CreateNewWallet(string uniqueMasterCitizenNumberValue,
                                                      string postalIndexNumber,
                                                      int supportedBankId,
                                                      string firstName,
                                                      string lastName)
        {
            SupportedBank supportedBank = await _unitOfWork.SupportedBankRepository.GetById(supportedBankId);

            if (supportedBank == null)
            {
                throw new ArgumentException($"Supported bank with id {supportedBankId} does not exist");
            }
            IBankAPI bankAPI     = _bankAPIDeterminator.DeterminateBankAPI(supportedBank);
            bool     validStatus = await bankAPI.CheckStatus(uniqueMasterCitizenNumberValue, postalIndexNumber);

            if (!validStatus)
            {
                throw new BankAPIException("Bank api - invalid status");
            }
            Wallet existingWallet = await _unitOfWork.WalletRepository.GetFirstOrDefault(Wallet =>
                                                                                         Wallet.UniqueMasterCitizenNumber.Value == uniqueMasterCitizenNumberValue
                                                                                         );

            if (existingWallet != null)
            {
                throw new ExistingWalletException("Wallet already exist with same UMCN");
            }
            UniqueMasterCitizenNumber uniqueMasterCitizenNumber = new UniqueMasterCitizenNumber(uniqueMasterCitizenNumberValue);

            if (!uniqueMasterCitizenNumber.ValidForPlatform())
            {
                throw new NotValidUniqueMasterCitizenNumberException("Unique master citizen number not valid for platform");
            }
            string walletPassword = PasswordGenerator.WalletPassword();
            Wallet wallet         = new Wallet(uniqueMasterCitizenNumberValue, supportedBank, firstName, lastName, walletPassword, postalIndexNumber);
            await _unitOfWork.WalletRepository.Insert(wallet);

            await _unitOfWork.SaveChangesAsync();

            return(new WalletDTO(wallet));
        }