コード例 #1
0
 partial void OnOrderChanging(Order newValue, Order oldValue);
コード例 #2
0
 partial void OnOrderChanged(Order value);
コード例 #3
0
        /// <summary>
        /// Process the order
        /// </summary>
        protected void wzdCheckOut_FinishButtonClick(object sender, WizardNavigationEventArgs e)
        {
            using (var context = new PetshopDataContext())
            {
                var profile = context.Profile.GetProfile(User.Identity.Name);
                if (profile.ShoppingCart.Count > 0)
                {
                    // display ordered items
                    CartListOrdered.Bind(profile.ShoppingCart);

                    // display total and credit card information
                    ltlTotalComplete.Text = ltlTotal.Text;
                    ltlCreditCardComplete.Text = ltlCreditCard.Text;

                    #region Create Order

                    var order = new Order();

                    order.UserId = profile.UniqueID.ToString();
                    order.OrderDate = DateTime.Now;
                    order.CreditCard = GetCreditCard();
                    order.Courier = order.CreditCard.CardType;
                    order.TotalPrice = CartHelper.GetTotal(profile.ShoppingCart);
                    order.AuthorizationNumber = 0;
                    order.Locale = "en-us";

                    #region Shipping Information

                    order.ShipAddr1 = billingForm.Address.Address1;
                    order.ShipAddr2 = billingForm.Address.Address2;
                    order.ShipCity = billingForm.Address.City;
                    order.ShipState = billingForm.Address.State;
                    order.ShipZip = billingForm.Address.Zip;
                    order.ShipCountry = billingForm.Address.Country;
                    order.ShipToFirstName = billingForm.Address.FirstName;
                    order.ShipToLastName = billingForm.Address.LastName;

                    #endregion

                    #region Billing Information

                    order.BillAddr1 = shippingForm.Address.Address1;
                    order.BillAddr2 = shippingForm.Address.Address2;
                    order.BillCity = shippingForm.Address.City;
                    order.BillState = shippingForm.Address.State;
                    order.BillZip = shippingForm.Address.Zip;
                    order.BillCountry = shippingForm.Address.Country;
                    order.BillToFirstName = shippingForm.Address.FirstName;
                    order.BillToLastName = shippingForm.Address.LastName;

                    #endregion
                    context.Order.InsertOnSubmit(order);
                    context.SubmitChanges();

                    #endregion

                    int itemsOnBackOrder = 0;
                    //Decrement and check the Inventory.
                    foreach (Cart cart in profile.ShoppingCart)
                    {
                        var inventory = context.Inventory.GetByKey(cart.ItemId);

                        if (cart.Quantity > inventory.Qty)
                        {
                            itemsOnBackOrder += cart.Quantity - inventory.Qty;
                        }

                        inventory.Qty -= cart.Quantity;
                        context.SubmitChanges();
                    }

                    if (itemsOnBackOrder > 0)
                    {
                        ItemsOnBackOrder.Text = string.Format("<br /><p style=\"color:red;\"><b>Backorder ALERT:</b> {0} items are on backorder.</p>", itemsOnBackOrder);
                    }

                    CartHelper.SaveOrderLineItems(profile.ShoppingCart, order.OrderId);

                    // destroy cart
                    CartHelper.ClearCart(profile.ShoppingCart);
                }
                else
                {
                    lblMsg.Text =
                        "<p><br>Can not process the order. Your cart is empty.</p><p class=SignUpLabel><a class=linkNewUser href=Default.aspx>Continue shopping</a></p>";
                    wzdCheckOut.Visible = false;
                }
            }
        }