Beispiel #1
0
        /// <summary>
        /// Executes the add referral API invocation.
        /// </summary>
        public void Execute()
        {
            SharedReferralLogic sharedReferralLogic = new SharedReferralLogic(Context, ReferralOperations);
            ResultSummary       resultSummary       = (ResultSummary)Context[Key.ResultSummary];

            ResultCode resultCode = ValidateParameters();

            if (resultCode == ResultCode.Success)
            {
                resultSummary.SetResultCode(sharedReferralLogic.AddReferral(UserIdString));
            }
            else
            {
                resultSummary.SetResultCode(resultCode);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Validates the user ID in the context.
        /// </summary>
        /// <param name="crud">
        /// The CRUD operation for which a token is being created.
        /// </param>
        /// <returns>
        /// The ResultCode corresponding to the result of the operation.
        /// </returns>
        /// <remarks>
        /// Authenticated user is automatically created within the system if necessary when validating the user ID in the
        /// context while obtaining a token for Create operations.
        /// </remarks>
        private ResultCode ValidateUserId(Crud crud)
        {
            ResultCode result = ResultCode.Success;

            // Attempt to retrieve the user.
            SharedUserLogic sharedUserLogic = new SharedUserLogic(Context, CommerceOperationsFactory.UserOperations(Context));
            User            user            = sharedUserLogic.RetrieveUser();

            // If the user is null and the CRUD operation is Create, implicitly create the user.
            if (user == null)
            {
                if (crud == Crud.Create)
                {
                    if (Context.ContainsKey(Key.CorrelationId) == true)
                    {
                        Guid userId = (Guid)Context[Key.GlobalUserId];
                        user = new User(userId, Guid.NewGuid());
                        Context[Key.User] = user;
                        sharedUserLogic.AddUser();

                        // Update analytics.
                        Analytics.AddRegisterUserEvent(userId, user.AnalyticsEventId, (Guid)Context[Key.CorrelationId], Context[Key.ReferrerId] as string);

                        // Add referral, if any.
                        SharedReferralLogic sharedReferralLogic = new SharedReferralLogic(Context,
                                                                                          CommerceOperationsFactory.ReferralOperations(Context));
                        sharedReferralLogic.AddReferral((string)Context[Key.ReferredUserId]);
                    }
                    else
                    {
                        Context.Log.Warning("No correlation ID could be found in the context.");
                        result = ResultCode.ParameterCannotBeNull;
                    }
                }
                else
                {
                    result = ResultCode.UnexpectedUnregisteredUser;
                }
            }

            return(result);
        }