예제 #1
0
        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);
        }
예제 #2
0
        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);
        }