コード例 #1
0
 private bool CanExecuteCardNumber()
 {
     return(CardNumber.All(char.IsDigit) && CardNumber.Length == 16);
 }
コード例 #2
0
        /// <summary>
        /// checks if credit card details are valid
        /// </summary>
        /// <returns>true if this card is valid</returns>
        public bool IsValid()
        {
            var len = CardNumber.Length;

            if (len == 0)
            {
                return(false);
            }


            // check for all numbers
            if (!CardNumber.All(char.IsDigit))
            {
                return(false);
            }
            if (!CardVerificationValue.All(char.IsDigit))
            {
                return(false);
            }

            if (CardVerificationValue.Length != 3)
            {
                return(false);
            }



            // Check card not expired

            if (Month > 12)
            {
                return(false);
            }

            var time = DateTime.Now;

            if (time.Year > Year)
            {
                return(false);
            }
            if (time.Year == Year && time.Month > Month)
            {
                return(false);
            }


            using (var db = new BankSystemContext())
            {
                var query = from card in db.CreditCards
                            where card.Month == this.Month &&
                            card.Year == this.Year &&
                            card.CardNumber == this.CardNumber &&
                            card.CardVerificationValue == this.CardVerificationValue
                            select card.BankAccount;

                BankAccountDetails found = query.FirstOrDefault();

                this.BankAccount = found;

                return(found != null);
            }
        }