public Task <HttpResponseMessage> Delete(Guid cardId) { Stopwatch callTimer = Stopwatch.StartNew(); Task <HttpResponseMessage> result; // Build a context object to pass down the pipeline. CommerceContext context = CommerceContext.BuildAsynchronousRestContext("Remove card", Request, new RemoveCardResponse(), callTimer); try { context[Key.CardId] = General.IntegerFromGuid(cardId); context.Log.Information("Processing {0} call.", context.ApiCallDescription); context.Log.Verbose("{0} request:\r\ncardId={1}", context.ApiCallDescription, cardId); // Add ID for the user making this call to the context. context[Key.GlobalUserId] = CommerceContext.PopulateUserId(context); context[Key.RewardProgramType] = ControllerHelper.GetRewardProgramAssociatedWithRequest(this.Request); // Create an executor object to execute the API invocation. RemoveCardExecutor removeCardExecutor = new RemoveCardExecutor(context); Task.Factory.StartNew(async() => await removeCardExecutor.Execute()); result = ((TaskCompletionSource <HttpResponseMessage>)context[Key.TaskCompletionSource]).Task; } catch (Exception ex) { result = RestResponder.CreateExceptionTask(context, ex); } return(result); }
public Task <HttpResponseMessage> Claim(ClaimDealPayload claimDealPayload) { Stopwatch callTimer = Stopwatch.StartNew(); Task <HttpResponseMessage> result; // Build a context object to pass down the pipeline. CommerceContext context = CommerceContext.BuildAsynchronousRestContext("Claim deal in partners and data store", Request, new ClaimDealResponse(), callTimer); try { context.Log.Information("Processing {0} call.", context.ApiCallDescription); CustomIdentity clientIdentity = (CustomIdentity)Thread.CurrentPrincipal.Identity; context.Log.Verbose("Presented credentials are for role \"{0}\" and include token \"{1}\".", clientIdentity.Name, clientIdentity.PresentedClientToken); context.Log.Verbose("{0} request:\r\n{1}", context.ApiCallDescription, General.SerializeJson(claimDealPayload)); // Add payload information to the context. context[Key.ClaimDealPayload] = claimDealPayload; // Create an executor object to execute the API invocation. ClaimDealExecutor claimDealExecutor = new ClaimDealExecutor(context); Task.Factory.StartNew(async() => await claimDealExecutor.Execute()); result = ((TaskCompletionSource <HttpResponseMessage>)context[Key.TaskCompletionSource]).Task; } catch (Exception ex) { result = RestResponder.CreateExceptionTask(context, ex); } return(result); }
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); }