Ejemplo n.º 1
0
        public void AddusersBilling(int count)
        {
            Sqrely_Identity identity = clsCommon.getIdentity();

            if (count > 0)
            {
                try
                {
                    ChargifyConnect Chargify = clsCommon.Chargify;
                    // Load the customer information for the current user
                    //ICustomer customer = Chargify.Find<Customer>(clsCommon.getCurrentUserBillingRefNumber());
                    // Alternate syntax
                    // Dim customer As ICustomer = Chargify.LoadCustomer(clsCommon.getCurrentUserBillingRefNumber())
                    tenant        currentenant        = db.tenant.Find(identity.tenatId);
                    ISubscription currentSubscription = ChargifyTools.getSubscription(currentenant.billingRefNumber);
                    if (currentSubscription != null)
                    {
                        int componentID = clsCommon.getComponentId(currentSubscription.Product.Handle);
                        if (componentID > 0)
                        {
                            //Update the amount allocated
                            //Dim info As IComponentAttributes = Chargify.UpdateComponentAllocationForSubscription(currentSubscription.SubscriptionID, componentID, (CInt(noUsersTb.Text) - 1))
                            //Dim info As IComponentAttributes = Chargify.UpdateComponentAllocationForSubscription(currentSubscription.SubscriptionID, componentID, newQuantity)
                            //Chargify.CreateComponentAllocation(currentSubscription.SubscriptionID, componentID, count, "New Users", ComponentUpgradeProrationScheme.No_Prorate, ComponentDowngradeProrationScheme.No_Prorate);
                            if (currentSubscription.State == SubscriptionState.Trialing)
                            {
                                Chargify.CreateComponentAllocation(currentSubscription.SubscriptionID, componentID, count, "New Users", ComponentUpgradeProrationScheme.No_Prorate, ComponentDowngradeProrationScheme.No_Prorate);
                            }
                            else
                            {
                                Chargify.CreateComponentAllocation(currentSubscription.SubscriptionID, componentID, count, "New Users", ComponentUpgradeProrationScheme.Prorate_Attempt_Capture, ComponentDowngradeProrationScheme.Prorate);
                            }
                        }
                        //Dim sqltext As String = "UPDATE tenant SET modifyDateTime=getdate(), " &
                        //" allocatedUsers = @allocatedUsers " &
                        //" WHERE billingRefNumber = @billingRefNumber"
                        //ApplicationBlocks.SqlHelper.ExecuteNonQuery(clsCommon.connString,
                        //                                        System.Data.CommandType.Text, sqltext,
                        //                                    New System.Data.SqlClient.SqlParameter("@allocatedUsers", noUsersTb.Text),
                        //                                    New System.Data.SqlClient.SqlParameter("@billingRefNumber", currentSubscription.Customer.SystemID))
                        //tenant tenant = default(tenant);
                        //tenant = (from t in db.tenantwhere t.billingRefNumber.Equals(currentSubscription.Customer.SystemID)).FirstOrDefault();

                        currentenant.allocatedUsers = count + 1;
                        //Dim identity As SQRely_Admin.SqrelySecurity.Sqrely_Identity
                        //identity = HttpContext.Current.User.Identity
                        currentenant.updatedById     = identity.Id;
                        currentenant.modifyDateTime  = DateTime.Now;
                        db.Entry(currentenant).State = EntityState.Modified;
                        db.SaveChanges();
                        //LoadSubscriptionInfo();
                        //usageResultLtr.Text = string.Format("Current Allocated users ({0}).", noUsersTb.Text);
                        //If newAddedUsers > 0 Then
                        //    ' Charge Existing Users on new account
                        //    Dim amount As Decimal = newAddedUsers * currentSubscription.ProductPrice
                        //    Chargify.CreateCharge(currentSubscription.SubscriptionID, amount, String.Format("New Users Added: {0}", newAddedUsers.ToString()), True)
                        //End If

                        //' Get the amount allocated
                        //Dim newInfo As IComponentAttributes = Chargify.GetComponentInfoForSubscription(currentSubscription.SubscriptionID, componentID)

                        //If newInfo IsNot Nothing Then
                        //    ' Charged OK
                        //    Me.usageResultLtr.Text = String.Format("Current additional users ({0}).", noUsersTb.Text)
                        //    ScriptManager.RegisterStartupScript(Me.Page, GetType(Page), "highlight", "HighlightResult();", True)
                        //Else
                        //    ' Not OK
                        //    Me.usageResultLtr.Text = String.Format("Error. ({0})", DateTime.Now.ToString())
                        //    ScriptManager.RegisterStartupScript(Me.Page, GetType(Page), "highlight", "HighlightResult();", True)
                        //End If
                    }
                }
                catch (Exception ex)
                {
                    //ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "error", "alert('" + ex.Message + "');", true);
                }
            }
        }