public Task <HttpResponseMessage> Add(NewCardNumber newCardNumber) { Stopwatch callTimer = Stopwatch.StartNew(); Task <HttpResponseMessage> result; // Build a context object to pass down the pipeline. CommerceContext context = CommerceContext.BuildAsynchronousRestContext("Add card and queue claiming already claimed deals", Request, new AddCardResponse(), callTimer); try { if (newCardNumber == null) { throw new ArgumentNullException("newCardNumber", "Parameter newCardNumber cannot be null."); } context.Log.Information("Processing {0} call.", context.ApiCallDescription); // Generate a legacy NewCardInfo object from the specified number. NewCardInfo newCardInfo = ControllerUtilities.GenerateLegacyCardInfo(newCardNumber); ControllerUtilities.LogObfuscatedNewCardInfo(newCardInfo, context); // Add parameters of the call to the context. context[Key.QueueJob] = true; context[Key.NewCardInfo] = newCardInfo; context[Key.GlobalUserId] = CommerceContext.PopulateUserId(context); context[Key.ReferrerId] = newCardNumber.Referrer; context[Key.RewardProgramType] = ControllerUtilities.GetRewardProgramAssociatedWithRequest(this.Request); // Create an executor object to execute the API invocation. AddCardExecutor executor = new AddCardExecutor(context); Task.Factory.StartNew(async() => await executor.Execute()); result = ((TaskCompletionSource <HttpResponseMessage>)context[Key.TaskCompletionSource]).Task; } catch (Exception ex) { result = RestResponder.CreateExceptionTask(context, ex); } return(result); }
public Task <HttpResponseMessage> Add(AddCardPayload payload) { Stopwatch callTimer = Stopwatch.StartNew(); if (payload == null) { throw new ArgumentNullException("payload", "Parameter payload cannot be null."); } // Build a context object to pass down the pipeline. CommerceContext context = CommerceContext.BuildAsynchronousRestContext("Create account for unauthenticated user, add card, and queue claiming deals", Request, new UnauthenticatedAddCardResponse(), callTimer); context.Log.Information("Processing {0} call.", context.ApiCallDescription); // Generate a legacy NewCardInfo object from the specified number. NewCardInfo newCardInfo = ControllerUtilities.GenerateLegacyCardInfo(new NewCardNumber { Number = payload.Number }); ControllerUtilities.LogObfuscatedNewCardInfo(newCardInfo, context); // Add parameters of the call to the context. context[Key.CreateUnauthenticatedAccount] = true; context[Key.EmailAddress] = payload.Email; context[Key.ReferrerId] = payload.Referrer; context[Key.UserLocation] = payload.UserLocation; context[Key.ReferralEvent] = ReferralEvent.Signup; context[Key.QueueJob] = true; context[Key.NewCardInfo] = newCardInfo; context[Key.RewardProgramType] = ControllerUtilities.GetRewardProgramAssociatedWithRequest(this.Request); // Create an executor object to execute the API invocation. AddCardExecutor executor = new AddCardExecutor(context); Task.Factory.StartNew(async() => await executor.Execute()); return(((TaskCompletionSource <HttpResponseMessage>)context[Key.TaskCompletionSource]).Task); }