コード例 #1
0
        public void RecommendAFriend(int referrerId, NewAccount friendsAccountDetails)
        {
            Validate(friendsAccountDetails);

            // most technologies have similar transaction APIs
            using (var transaction = new System.Transactions.TransactionScope())
            {
                try
                {
                    // customerDirectory is a domain repository
                    var referrer = customerDirectory.Find(referrerId);
                    var friend   = customerDirectory.Add(friendsAccountDetails);
                    // referAFriend policy is a domain policy
                    referAFriendPolicy.Apply(referrer, friend);

                    transaction.Complete();

                    // log here to keep to avoid cluttering domain
                    logger.Debug("Successful friend recommendation");
                    StatsdClient.Metrics.Counter("friendReferrals");
                }
                catch (ReferralRejectedDueToLongTermOutstandingBalance ex)
                {
                    logger.Error(ex);
                    StatsdClient.Metrics.Counter("ReferralRejected");
                    throw new ApplicationError(
                              "Sorry, this referral cannot be completed. The referrer " +
                              "currently has an outstanding balance. Please contact " +
                              "customer support"
                              );
                    // transaction will roll back if Complete() not called
                }
            }
        }
コード例 #2
0
        public void RecommendAFriend(int referrerId, NewAccount friendsAccountDetails)
        {
            Validate(friendsAccountDetails);

            using (var transaction = new System.Transactions.TransactionScope())
            {
                try
                {
                    var referrer = customerDirectory.Find(referrerId);
                    var friend   = customerDirectory.Add(friendsAccountDetails);
                    referAFriendPolicy.Apply(referrer, friend);

                    transaction.Complete();

                    var msg = new CustomerRegisteredViaReferralPolicy
                    {
                        ReferrerId = referrerId,
                        FriendId   = friend.Id
                    };
                    bus.Publish(msg);
                }
                catch (ReferralRejectedDueToLongTermOutstandingBalance)
                {
                    var msg = new ReferralSignupRejected
                    {
                        ReferrerId  = referrerId,
                        FriendEmail = friendsAccountDetails.Email,
                        Reason      = "Referrer has long term outstanding balance"
                    };
                    bus.Publish(msg);
                }
            }
        }
コード例 #3
0
        // all infrastructure concerns handled by framework
        public ActionResult Index(int referrerId, NewAccount friend)
        {
            var referrer = directory.Find(referrerId);
            var newAcct  = directory.Create(friend);

            policy.Apply(referrer, newAcct);

            return(View());
        }
        public async void ReferAFriend(int referrerId, NewAccount friend)
        {
            // ...
            var referrer = await directory.Find(referrerId);

            var newAcct = await directory.Create(friend);

            policy.Apply(referrer, newAcct);
            // ...
        }