/// <summary> /// Adds the specified referral to the system. /// </summary> /// <param name="referralDataContract"> /// The referral to add to the system. /// </param> /// <returns> /// An HttpResponseMessage containing an AddReferralResponse with detailed result information. /// </returns> public HttpResponseMessage Add(ReferralDataContract referralDataContract) { Stopwatch callTimer = Stopwatch.StartNew(); HttpResponseMessage result; // Build a context object to pass down the pipeline. CommerceContext context = CommerceContext.BuildSynchronousRestContext("Add user referral", Request, new AddReferralResponse(), callTimer); try { context.Log.Information("Processing {0} call.", context.ApiCallDescription); context[Key.ReferralDataContract] = referralDataContract; context.Log.Verbose("{0} request:\r\n{1}", context.ApiCallDescription, General.SerializeJson(referralDataContract)); // Create an executor object to execute the API invocation. context[Key.ReferredUserFirstEarnRewardAmount] = CommerceServiceConfig.Instance.ReferredUserFirstEarnRewardAmount; context[Key.ReferredUserFirstEarnRewardExplanation] = CommerceServiceConfig.Instance.ReferredUserFirstEarnRewardExplanation; AddReferralExecutor executor = new AddReferralExecutor(context); executor.Execute(); // Build the response from the result of API invocation. result = RestResponder.BuildSynchronousResponse(context); } catch (Exception ex) { result = RestResponder.BuildSynchronousResponse(context, ex); } return(result); }
/// <summary> /// Validates parameters within the context. /// </summary> /// <returns> /// The result of the operation. /// </returns> private ResultCode ValidateParameters() { ResultCode result = ResultCode.Success; ReferralDataContract referralDataContract = Context[Key.ReferralDataContract] as ReferralDataContract; bool stepResult = referralDataContract != null; if (stepResult == true) { ReferralTypeCode = referralDataContract.ReferralTypeCode; Context[Key.ReferralTypeCode] = ReferralTypeCode; stepResult = String.IsNullOrWhiteSpace(ReferralTypeCode) == false; } if (stepResult == true) { UserIdString = referralDataContract.UserId; Context[Key.ReferredUserId] = UserIdString; stepResult = String.IsNullOrWhiteSpace(UserIdString) == false; } if (stepResult == true) { ReferralEvent referralEvent = (ReferralEvent)referralDataContract.ReferralEvent; Context[Key.ReferralEvent] = referralEvent; ReferralEventString = referralEvent.ToString(); } else { result = ResultCode.InvalidParameter; } return(result); }