Exemple #1
0
        public BankCard CreateBankCard(Client client, string pin, int expireYears)
        {
            if (String.IsNullOrWhiteSpace(pin))
            {
                throw new ArgumentNullException(nameof(pin), "PIN can not be null");
            }

            if (!BankCardValidation.PinValidate(pin))
            {
                throw new BankCardException("PIN must be numeric value!");
            }


            var bankCard = new BankCard
            {
                BankName   = Name,
                Fullname   = BankHelper.GetFullName(client.Name, client.Surname),
                CardNumber = BankHelper.GetRandomPan(),
                PIN        = pin,
                CVC        = BankHelper.GetRandomCvc(),
                ExpireDate = BankHelper.GetExpireDate(expireYears),
                Balance    = BankHelper.GetRandomBalance()
            };

            return(bankCard);
        }
Exemple #2
0
        public void Withdraw(BankCard bankCard, double amount)
        {
            if (amount > bankCard.Balance)
            {
                throw new InsufficientAmountException("There is no sufficient amount in balance");
            }

            bankCard.Balance -= amount;
        }
Exemple #3
0
        public void CardToCard(BankCard from, string toPan, double amount)
        {
            var client = Array.Find(Clients, client1 => client1.ClientCard.CardNumber == toPan);

            if (client != null)
            {
                if (amount > from.Balance)
                {
                    throw new InsufficientAmountException($"There is no sufficient amount this card -> {toPan}");
                }

                from.Balance -= amount;
                client.ClientCard.Balance += amount;
            }
            else
            {
                throw new ClientException($"There is no Card associated this PAN -> {toPan}");
            }
        }