// technical validation carried out at the application level
        private void Validate(NewAccount account)
        {
            if (!account.Email.Contains("@"))
                throw new ValidationFailure("Not a valid email address");

            if (account.Email.Length >= 50)
                throw new ValidationFailure("Email address must be less than 50 characters");

            if (account.Nickname.Length >= 25)
                throw new ValidationFailure("Nickname must be less than 25 characters");

            if (String.IsNullOrWhiteSpace(account.Email))
                throw new ValidationFailure("You must supply an email");

            if (String.IsNullOrWhiteSpace(account.Nickname))
                throw new ValidationFailure("You must supply a Nickname");
        }
        public void RecommendAFriend(int referrerId, NewAccount friendsAccountDetails)
        {
            Validate(friendsAccountDetails);

            // most technologies have similar transaction APIs
            using (var transaction = new System.Transactions.TransactionScope())
            {
                try
                {
                    // ... interact with domain multiple times
                    transaction.Complete();
                }
                catch(ReferralRejectedDueToLongTermOutstandingBalance)
                {
                    throw new ApplicationError(
                        "Sorry, this referral cannot be completed. The referrer " +
                        "currently has an outstanding balance. Please contact " +
                        "Customer Services"
                    );
                    // transaction will roll back if Complete() not called
                }
            }
        }
Exemple #3
0
        public void RecommendAFriend(int referrerId, NewAccount friendsAccountDetails)
        {
            Validate(friendsAccountDetails);

            // most technologies have similar transaction APIs
            using (var transaction = new System.Transactions.TransactionScope())
            {
                try
                {
                    // ... interact with domain multiple times
                    transaction.Complete();
                }
                catch (ReferralRejectedDueToLongTermOutstandingBalance)
                {
                    throw new ApplicationError(
                              "Sorry, this referral cannot be completed. The referrer " +
                              "currently has an outstanding balance. Please contact " +
                              "Customer Services"
                              );
                    // transaction will roll back if Complete() not called
                }
            }
        }