/// <summary> /// Handler for Delete/Move buttons /// </summary> protected void CartItem_Command(object sender, CommandEventArgs e) { Profile profile = ProfileManager.Instance.GetCurrentUser(Page.User.Identity.Name); var cartService = new CartService(); switch (e.CommandName) { case "Del": cartService.Delete(profile.CartCollection.Find(c => c.ItemId == e.CommandArgument.ToString())); break; case "Move": cartService.Delete(profile.CartCollection.Find(c => c.ItemId == e.CommandArgument.ToString())); profile.CartCollection.Add(new Cart() { ItemId = e.CommandArgument.ToString(), UniqueId = profile.UniqueId, IsShoppingCart = true }); break; } BindCart(); }
/// <summary> /// Process the order /// </summary> protected void wzdCheckOut_FinishButtonClick(object sender, WizardNavigationEventArgs e) { var inventoryService = new InventoryService(); Profile profile = ProfileManager.Instance.GetCurrentUser(Page.User.Identity.Name); if (profile.CartCollection.Count > 0) { // display ordered items CartListOrdered.Bind(profile.CartCollection); // 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 = profile.CartCollection.Sum(c => c.Total); 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 var orderService = new OrderService(); orderService.DeepSave(order); #endregion int itemsOnBackOrder = 0; //Decrement and check the Inventory. foreach (Cart cart in profile.CartCollection) { Inventory inventory = inventoryService.GetByItemId(cart.ItemId); if(cart.Quantity > inventory.Qty) { itemsOnBackOrder += cart.Quantity - inventory.Qty; } inventory.Qty -= cart.Quantity; #region Reset the Inventory back to 10,000 if (inventory.Qty < 0) inventory.Qty = 10000; #endregion inventoryService.DeepSave(inventory); } if(itemsOnBackOrder > 0) { ItemsOnBackOrder.Text = string.Format("<br /><p style=\"color:red;\"><b>Backorder ALERT:</b> {0} items are on backorder.</p>", itemsOnBackOrder); } var cartService = new CartService(); cartService.SaveOrderLineItems(order.OrderId, profile.CartCollection); //profile.CartCollection.SaveOrderLineItems(order.OrderId); // destroy cart cartService.Delete(profile.CartCollection); } 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; } }