public void CreateTestObject() { string errorMessage; string userName = string.Format("TestUser_{0}", new Random().Next(1, 100000)); string email = string.Format("TestUser_{0}@gmail.com", new Random().Next(1, 100000)); MembershipCreateStatus status; MembershipUser newuser = Membership.CreateUser(userName, "john!!dD0122", email, "Apple is good?", "Apple", true, out status); if (newuser != null && newuser.ProviderUserKey != null) { PaymentInfoTestObject = new PaymentInfo { UserId = (Guid)newuser.ProviderUserKey, CreditCardNumber = "1234432112344321", ExpirationDate = DateTime.Now.AddDays(100), CCV = 892, BillingAddress = "TestAddress", BillingCity = "TestCity", BillingState = "FL", BillingZip = "31233" }; } PaymentInfoManager.Save(PaymentInfoTestObject, out errorMessage); }
/// <summary> /// Save PaymentInfo Entity /// </summary> /// <param name="item">Entity to save</param> /// <param name="errorMessage">Error Message</param> /// <returns>return true if save successfully, else return false</returns> public static bool Save(PaymentInfo item, out string errorMessage) { bool isValid = Validate(item, out errorMessage); if (isValid) { PaymentInfoDao.Save(item); } return isValid; }
/// <summary> /// Saves a PaymentInfo to the data store. /// </summary> /// <param name="item">The item to save</param> public static void Save(PaymentInfo item) { if (item.IsItemModified) { if (item.PaymentInfoId == null) { item.PaymentInfoId = Insert(item); } else { Update(item); } } }
/// <summary> /// Validate PaymentInfo Entity /// </summary> /// <param name="item">Entity to validate</param> /// <param name="errorMessage">error message if validation failed</param> /// <returns>return true if entity passes validation logic, else return false</returns> public static bool Validate(PaymentInfo item, out string errorMessage) { MembershipUser user = Membership.GetUser(item.UserId); StringBuilder builder = new StringBuilder(); if (user == null) { builder.AppendHtmlLine("*UserId must be valid"); } if (item.CreditCardNumber.IsNullOrWhiteSpace()) { builder.AppendHtmlLine("*CreditCardNumber is required"); } if (!item.ExpirationDate.IsValidWithSqlDateStandards()) { builder.AppendHtmlLine("*ExpirationDate is required and must be valid"); } if (item.BillingAddress.IsNullOrWhiteSpace()) { builder.AppendHtmlLine("*Billing Address is required"); } if (item.CreditCardNumber.Length != 16) { builder.AppendHtmlLine("*Credit Card Number must be 16 digits"); } if (!item.CreditCardNumber.IsNumeric()) { builder.AppendLine("*Credit Card Number must be a 16 digit number"); } errorMessage = builder.ToString(); return errorMessage.IsNullOrWhiteSpace(); }
/// <summary> /// Updates a PaymentInfo /// </summary> /// <param name="item">The PaymentInfo item to save</param> private static void Update(PaymentInfo item) { List<SqlParameter> parameters = new List<SqlParameter> { new SqlParameter("@PaymentInfoId", item.PaymentInfoId), new SqlParameter("@UserId", item.UserId), new SqlParameter("@CreditCardNumber", item.CreditCardNumber), new SqlParameter("@ExpirationDate", item.ExpirationDate), new SqlParameter("@CCV", item.CCV), new SqlParameter("@BillingAddress", item.BillingAddress), new SqlParameter("@BillingCity", item.BillingCity), new SqlParameter("@BillingState", item.BillingState), new SqlParameter("@BillingZip", item.BillingZip) }; DataManager.ExecuteProcedure(KarzPlusConnectionString, "PKP_UpdatePaymentInfo", parameters); }
/// <summary> /// Inserts a new PaymentInfo /// </summary> /// <param name="item">The PaymentInfo item to insert</param> /// <returns>The id of the PaymentInfo item just inserted</returns> private static int Insert(PaymentInfo item) { List<SqlParameter> parameters = new List<SqlParameter> { new SqlParameter("@UserId", item.UserId), new SqlParameter("@CreditCardNumber", item.CreditCardNumber), new SqlParameter("@ExpirationDate", item.ExpirationDate), new SqlParameter("@CCV", item.CCV), new SqlParameter("@BillingAddress", item.BillingAddress), new SqlParameter("@BillingCity", item.BillingCity), new SqlParameter("@BillingState", item.BillingState), new SqlParameter("@BillingZip", item.BillingZip) }; return Convert.ToInt32(DataManager.ExecuteScalarProcedure(KarzPlusConnectionString, "PKP_InsertPaymentInfo", parameters)); }
protected void grdPaymentInfo_OnUpdateCommand(object sender, GridCommandEventArgs e) { if (e.Item is GridDataItem && e.Item.OwnerTableView.Name.SafeEquals("grdPaymentInfo", StringComparison.CurrentCultureIgnoreCase)) { GridDataItem item = e.Item as GridDataItem; int paymentInfoId = (int)item.GetDataKeyValue("PaymentInfoId"); HideErrorMessage(item); RadNumericTextBox txtCreditCardNumber = item.FindControl("txtCreditCardNumber") as RadNumericTextBox; RadDatePicker dtExpirationDate = item.FindControl("dtExpirationDate") as RadDatePicker; RadNumericTextBox txtCCV = item.FindControl("txtCCV") as RadNumericTextBox; RadTextBox txtBillingAddress = item.FindControl("txtBillingAddress") as RadTextBox; RadTextBox txtCity = item.FindControl("txtCity") as RadTextBox; RadTextBox txtZip = item.FindControl("txtZip") as RadTextBox; RadComboBox ddlStates = item.FindControl("ddlStates") as RadComboBox; bool canEdit = txtBillingAddress != null && dtExpirationDate != null && txtCCV != null && txtCity != null && txtZip != null && txtCreditCardNumber != null && ddlStates != null; if (canEdit) { PaymentInfo info = new PaymentInfo { BillingAddress = txtBillingAddress.Text, BillingCity = txtCity.Text, BillingState = ddlStates.SelectedValue, UserId = UserId, ExpirationDate = dtExpirationDate.SelectedDate.GetValueOrDefault(), BillingZip = txtZip.Text, CreditCardNumber = txtCreditCardNumber.Text, CCV = Convert.ToInt32(txtCCV.Value), IsItemModified = true }; info.PaymentInfoId = paymentInfoId; string errorMessage; if (!PaymentInfoManager.Save(info, out errorMessage)) { ShowErrorMessage(item, errorMessage); e.Canceled = true; } } else { ShowErrorMessage(item, "*There was a problem processing your request. Please try again."); e.Canceled = true; } } }