コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the GetUsersReferralsExecutor class.
        /// </summary>
        /// <param name="context">
        /// The context describing the referral type to register.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Parameter context cannot be null.
        /// </exception>
        public GetUsersReferralsExecutor(CommerceContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context", "Parameter context cannot be null.");
            }

            Context            = context;
            ReferralOperations = CommerceOperationsFactory.ReferralOperations(Context);
        }
コード例 #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);
        }