当前位置: 首页>>代码示例>>C#>>正文


C# PatchRequest.Add方法代码示例

本文整理汇总了C#中PatchRequest.Add方法的典型用法代码示例。如果您正苦于以下问题:C# PatchRequest.Add方法的具体用法?C# PatchRequest.Add怎么用?C# PatchRequest.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PatchRequest的用法示例。


在下文中一共展示了PatchRequest.Add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Activate

        public ActionResult Activate(string id)
        {
            if (!string.IsNullOrEmpty(id))
            {
                var apiContext = Common.GetApiContext();
                var plan = Plan.Get(apiContext, id);
                if (plan != null && plan.state == "CREATED")
                {
                    var patchRequest = new PatchRequest();
                    var tempPlan = new Plan();
                    tempPlan.state = "ACTIVE";
                    patchRequest.Add(new Patch { path = "/", op = "replace", value = tempPlan });
                    plan.Update(apiContext, patchRequest);

                    TempData["success"] = "Plan activated";
                }
            }

            return RedirectToAction("Index");
        }
开发者ID:malevolence,项目名称:PayPalTesting,代码行数:20,代码来源:PlansController.cs

示例2: AgreementUpdateTest

        public void AgreementUpdateTest()
        {
            // Get the agreement to be used for verifying the update functionality
            var apiContext = TestingUtil.GetApiContext();
            var agreementId = "I-HP4H4YJFCN07";
            var agreement = Agreement.Get(apiContext, agreementId);

            // Create an update for the agreement
            var updatedDescription = Guid.NewGuid().ToString();
            var patch = new Patch();
            patch.op = "replace";
            patch.path = "/";
            patch.value = new Agreement() { description = updatedDescription };
            var patchRequest = new PatchRequest();
            patchRequest.Add(patch);

            // Update the agreement
            agreement.Update(apiContext, patchRequest);

            // Verify the agreement was successfully updated
            var updatedAgreement = Agreement.Get(apiContext, agreementId);
            Assert.AreEqual(agreementId, updatedAgreement.id);
            Assert.AreEqual(updatedDescription, updatedAgreement.description);
        }
开发者ID:ruanzx,项目名称:PayPal-NET-SDK,代码行数:24,代码来源:AgreementTest.cs

示例3: Create

        public ActionResult Create(BillingPlan billingPlan)
        {
            if (ModelState.IsValid)
            {
                var apiContext = Common.GetApiContext();

                var plan = new Plan();
                plan.description = billingPlan.Description;
                plan.name = billingPlan.Name;
                plan.type = billingPlan.PlanType;

                plan.merchant_preferences = new MerchantPreferences
                {
                    initial_fail_amount_action = "CANCEL",
                    max_fail_attempts = "3",
                    cancel_url = "http://localhost:50728/plans",
                    return_url = "http://localhost:50728/plans"
                };

                plan.payment_definitions = new List<PaymentDefinition>();

                var paymentDefinition = new PaymentDefinition();
                paymentDefinition.name = "Standard Plan";
                paymentDefinition.amount = new Currency { currency = "USD", value = billingPlan.Amount.ToString() };
                paymentDefinition.frequency = billingPlan.Frequency.ToString();
                paymentDefinition.type = "REGULAR";
                paymentDefinition.frequency_interval = "1";

                if (billingPlan.NumberOfCycles.HasValue)
                {
                    paymentDefinition.cycles = billingPlan.NumberOfCycles.Value.ToString();
                }

                plan.payment_definitions.Add(paymentDefinition);

                var created = plan.Create(apiContext);

                if (created.state == "CREATED")
                {
                    var patchRequest = new PatchRequest();
                    patchRequest.Add(new Patch { path = "/", op = "replace", value = new Plan() { state = "ACTIVE" } });
                    created.Update(apiContext, patchRequest);
                }

                TempData["success"] = "Billing plan created.";
                return RedirectToAction("Index");
            }

            AddDropdowns();
            return View(billingPlan);
        }
开发者ID:malevolence,项目名称:PayPalTesting,代码行数:51,代码来源:PlansController.cs

示例4: Edit

        public ActionResult Edit(string id, CreditCard creditCard)
        {
            if (ModelState.IsValid)
            {
                var apiContext = Common.GetApiContext();

                creditCard.type = Common.GetCardType(creditCard.number);
                var existing = CreditCard.Get(apiContext, id);
                if (existing != null)
                {
                    var patchRequest = new PatchRequest();

                    // determine what's changed between the existing card
                    // and the posted values
                    if (creditCard.expire_month != existing.expire_month)
                    {
                        patchRequest.Add(new Patch { op = "replace", path = "/expire_month", value = creditCard.expire_month });
                    }

                    if (creditCard.expire_year != existing.expire_year)
                    {
                        patchRequest.Add(new Patch { op = "replace", path = "/expire_year", value = creditCard.expire_year });
                    }

                    if (!string.IsNullOrEmpty(creditCard.first_name) && creditCard.first_name != existing.first_name)
                    {
                        patchRequest.Add(new Patch { op = "replace", path = "/first_name", value = creditCard.first_name });
                    }

                    if (!string.IsNullOrEmpty(creditCard.last_name) && creditCard.last_name != existing.last_name)
                    {
                        patchRequest.Add(new Patch { op = "replace", path = "/last_name", value = creditCard.last_name });
                    }

                    if (patchRequest.Count > 0)
                    {
                        existing.Update(apiContext, patchRequest);

                        TempData["success"] = "Stored Card updated.";

                        return RedirectToAction("Details", new { id });
                    }
                    else
                    {
                        TempData["info"] = "Nothing to update";
                    }
                }
            }
            else
            {
                TempData["info"] = "ModelState is invalid";
            }

            AddPaymentDropdowns();
            return View(creditCard);
        }
开发者ID:malevolence,项目名称:PayPalTesting,代码行数:56,代码来源:CardsController.cs


注:本文中的PatchRequest.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。