protected void Button_Click(object sender, EventArgs e) { var button = sender as Button; if (button == null) return; var commandName = button.CommandName; if (string.IsNullOrEmpty(commandName)) return; int? id; switch (commandName.ToLower()) { case "ship": { id = TextHelper.ToInteger(button.CommandArgument); if (id == null) return; //Set Selected Address Id SelectedAddressId = (int)id; //Go to next index wiz_cart.MoveTo(wiz_cart.WizardSteps[1]); //Bind Cart GvCart_DataBind(); } break; case "nextship": { var userBillingAddress = new UserBillingAddress { FullName = txt_fullname.Text, AddressLine1 = txt_address1.Text, AddressLine2 = txt_address2.Text, City = txt_city.Text, State = txt_state.Text, CountryId = TextHelper.ToInteger(ddl_country.SelectedValue), PostalCode = txt_postalcode.Text, PhoneNumber = txt_phone.Text, UserId = LoggedInUserId, IsActive = true//Get from session }; int returnId; if (!_userBillingAddress.Insert(userBillingAddress, out returnId)) return; SelectedAddressId = returnId; //Set selectedAddressId so that system won't re-add the data again //Bind Cart GvCart_DataBind(); //Clear all fields txt_fullname.Text = string.Empty; txt_address1.Text = string.Empty; txt_address2.Text = string.Empty; txt_city.Text = string.Empty; txt_state.Text = string.Empty; txt_phone.Text = string.Empty; ddl_country.SelectedIndex = 0; //Move to next step MoveToNextStep(1); } break; case "nextpayment": { MoveToNextStep(2); } break; case "makepayment": { //Check if shopping cart is empty if (ShoppingCart == null || ShoppingCart.Count == 0) return; //Check if address is selected if (SelectedAddressId == 0) return; //Use transaction to make sure all queries run without error using (var ts = new TransactionScope()) { var order = new Order { CardNumber = txt_cardNumber.Text, SecurityNumber = TextHelper.ToInteger(txt_securityNumber.Text), NameOnCard = txt_nameOnCard.Text, ExpirationMonth = TextHelper.ToInteger(ddl_month.SelectedValue), ExpirationYear = TextHelper.ToInteger(ddl_year.SelectedValue), UserBillingAddressId = SelectedAddressId, UserId = LoggedInUserId, //get from session OrderItems = GetOrderItems() }; int orderNumber; if (_orderClass.Insert(order, out orderNumber)) { Session["Order"] = orderNumber; ts.Complete(); } } ShoppingCart = null; MoveToNextStep(3); } break; case "remove": id = TextHelper.ToInteger(button.CommandArgument); if (id == null) return; if (_userBillingAddress.Delete((int)id)) { DlAddress_DataBind(); } break; } }
private void detach_Orders(Order entity) { this.SendPropertyChanging(); entity.UserBillingAddress = null; }
partial void DeleteOrder(Order instance);
partial void UpdateOrder(Order instance);
partial void InsertOrder(Order instance);
private void attach_Orders(Order entity) { this.SendPropertyChanging(); entity.User = this; }