Example #1
0
 private void SavePlan(tblPlan plan)
 {
     // Save the plan to the database
     try
     {
         db.Entry(plan).State = System.Data.Entity.EntityState.Added;
         intSaveStatus        = db.SaveChanges();
     }
     catch (EntityException ex)
     {
         MessageBox.Show(ex.Message, "Save", MessageBoxButton.OK, MessageBoxImage.Error);
         throw;
     }
 }
    private void PopulateControlsBasedOnPlan()
    {
        _Plan = _Data.NWODC.tblPlans.Where(a => a.ID == Convert.ToInt32(ddlPaymentOption.SelectedValue)).SingleOrDefault();
        if (_Plan != null)
        {
            if (_Plan.ID != 1)
            {
                imgbtnBuyNow.Enabled      = true;
                imgbtnBuyNow.Visible      = true;
                btnApplyFreeOffer.Enabled = false;
                btnApplyFreeOffer.Visible = false;
            }
            else
            {
                imgbtnBuyNow.Enabled      = false;
                imgbtnBuyNow.Visible      = false;
                btnApplyFreeOffer.Enabled = true;
                btnApplyFreeOffer.Visible = true;
            }

            lblTotal.Text  = string.Format("{0:C}", _Plan.TotalAmount);
            lblMonths.Text = _Plan.Units.ToString();

            if (_Campaign.ExpiryDate == null)
            {
                lblEstimatedExpirationDate.Text = string.Format("{0:ddd, MMM d, yyyy}", DateTime.Now.AddMonths(_Plan.Units));
            }
            else
            {
                lblEstimatedExpirationDate.Text = string.Format("{0:ddd, MMM d, yyyy}", ((DateTime)_Campaign.ExpiryDate).AddMonths(_Plan.Units));
            }
        }
        else
        {
            imgbtnBuyNow.Enabled = false;
            ThrowError(this, new ControlErrorArgs()
            {
                InnerException = new Exception("Validation of Plan for ProfileID" +
                                               ddlPaymentOption.SelectedValue + ", " + _Profile.ID + " has been provided by user. Request came from user: "******" from IP: " +
                                               Request.UserHostAddress),
                Message  = "Invalid Profile.",
                Severity = 1
            });
        }
    }
Example #3
0
        private void lstPlans_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // Populate the controls with the new data when we select a different plan from the list.
            dbOp = dbOperation.Edit;

            stkAddEdit.Visibility     = Visibility.Visible;
            stkPlanButtons.Visibility = Visibility.Hidden;
            selectedPlan = plans.ElementAt(lstPlans.SelectedIndex);
            if (selectedPlan.planID > 0)
            {
                txbPlanID.Text   = selectedPlan.planID.ToString();
                txbPlanName.Text = selectedPlan.planName;
                txbPlanDesc.Text = selectedPlan.planDescription;
                txbPrice.Text    = selectedPlan.planPrice.ToString();
                cmbDuration.Text = selectedPlan.planTerm;
            }
        }
Example #4
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            // We are creating a new record in the plan database table
            if (dbOp == dbOperation.Add)
            {
                if (ValidateInput() == true)
                {
                    tblPlan plan = new tblPlan();
                    plan.planName        = txbPlanName.Text.Trim();
                    plan.planDescription = txbPlanDesc.Text.Trim();
                    plan.planPrice       = int.Parse(txbPrice.Text.Trim());
                    plan.planTerm        = cmbDuration.Text;

                    SavePlan(plan);

                    if (intSaveStatus == 1)
                    {
                        resetControls();
                        MessageBox.Show("New Plan created", "Save", MessageBoxButton.OK, MessageBoxImage.Information);

                        refreshPlanList();
                    }
                    else
                    {
                        MessageBox.Show("Unable to Save Plan", "Save", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                else
                {
                    MessageBox.Show(errMsg, "Save", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                // This is the update of an existing plan.
                if (ValidateInput() == true)
                {
                    foreach (var plan in db.tblPlans.Where(d => d.planID == selectedPlan.planID))
                    {
                        selectedPlan.planID          = int.Parse(txbPlanID.Text.Trim());
                        selectedPlan.planName        = txbPlanName.Text.Trim();
                        selectedPlan.planDescription = txbPlanDesc.Text.Trim();
                        selectedPlan.planPrice       = int.Parse(txbPrice.Text.Trim());
                        selectedPlan.planTerm        = cmbDuration.Text;
                    }

                    intSaveStatus = db.SaveChanges();

                    if (intSaveStatus == 1)
                    {
                        refreshPlanList();

                        MessageBox.Show("Plan Updated", "Update", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        MessageBox.Show("Unable to Update Plan", "Update", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
                else
                {
                    MessageBox.Show(errMsg, "Update", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }