Exemplo n.º 1
0
        //[RequireBasicAuthentication("AppHarbor")]
        public ActionResult Create(ProvisioningRequest provisionRequest)
        {
            if (provisionRequest == null || string.IsNullOrEmpty(provisionRequest.plan)) provisionRequest = new ProvisioningRequest() { callback_url = "/Response", heroku_id = Guid.NewGuid().ToString(), plan = "Free" };
            var db = new Database("DefaultConnection");
            Plan plan;
            if (!Enum.TryParse<Plan>(provisionRequest.plan, true, out plan))
            {
                throw new ArgumentException(string.Format("Plan \"{0}\" is not a valid plan", provisionRequest.plan));
            }

            var purchase = new Purchase()
            {
                CreatedBy = string.Format("{0};{1}", Request.GetForwardedHostAddress(), User.Identity.Name),
                UniqueId = Guid.NewGuid().ToString(),
                Plan = plan,
                ProviderId = provisionRequest.heroku_id,
                ProvisionStatus = ProvisionStatus.Provisioning,
                ApiKey = Guid.NewGuid().ToString(),
                ApiSecretKey = Guid.NewGuid().ToString()
            };
            // TODO: Provision the resource
            purchase.ProvisionStatus = ProvisionStatus.Provisioned;
            Purchase.Save(db, purchase);
            var output = new
            {
                id = purchase.UniqueId,
                config = new
                {
                    CONFIG_ApiKey = purchase.ApiKey,
                    CONFIG_ApiSecretKey = purchase.ApiSecretKey
                }
            };

            return Json(output, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 2
0
 public static void Save(Database db, Purchase purchase)
 {
     var existing = db.SingleOrDefault<Purchase>("SELECT * FROM purchases WHERE UniqueId=@0 ", purchase.UniqueId);
     if (existing != null)
         db.Update("purchases", "PurchaseId", existing);
     else
         db.Insert("purchases", "PurchaseId", purchase);
 }