protected void ViewCartButton_Click(object sender, EventArgs e)
        {
            MainView.ActiveViewIndex = 1;
            ApplicationUserManager userManager = new ApplicationUserManager(new
                                                                            UserStore <ApplicationUser>(new ApplicationDbContext()));
            string userName   = Context.User.Identity.GetUserName();
            int    employeeid = 0;

            if (!string.IsNullOrEmpty(userName))
            {
                employeeid     = userManager.Get_CurrentEmployeeIDFromUserName(userName);
                UserName2.Text = userName;
                UserID2.Text   = employeeid.ToString();
            }
            CartListView.DataBind();
        }
        protected void UpdateCartItem_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            int    shoppingCartItemID = int.Parse(e.CommandArgument.ToString());
            string itemDescription    = (e.Item.FindControl("DescriptionLabel") as Label).Text;

            if ((e.Item.FindControl("DeleteCheckBox") as CheckBox).Checked)
            {
                MessageUserControl.TryRun(() =>
                {
                    ShoppingCartItemController sysmgr = new ShoppingCartItemController();
                    sysmgr.Delete_ShoppingCartItem(shoppingCartItemID);
                    CartListView.DataBind();
                }, "Item Deleted", itemDescription + " has been removed from your shopping cart.");
            }
            else
            {
                int    qty = 0;
                bool   quantityInputFail = false;
                string inputQty          = (e.Item.FindControl("QuantitySelectedLabel") as TextBox).Text;
                if (!(int.TryParse(inputQty, out qty)))
                {
                    quantityInputFail = true;
                }
                if (quantityInputFail)
                {
                    MessageUserControl.ShowInfo("Could not update item quantity. Quantity must be a valid integer.");
                }
                else
                {
                    MessageUserControl.TryRun(() =>
                    {
                        ShoppingCartItemController sysmgr = new ShoppingCartItemController();
                        ShoppingCartItem item             = sysmgr.Get_ShoppingCartItem(shoppingCartItemID);
                        item.Quantity = qty;
                        sysmgr.Update_ShoppingCartItem(item);
                        CartListView.DataBind();
                    }, "Item Quantity Updated", itemDescription + " has had its quantity updated.");
                }
            }
            MainView.ActiveViewIndex = 1;
        }
        protected void OrderButton_Click(object sender, EventArgs e)
        {
            ApplicationUserManager userManager = new ApplicationUserManager(new
                                                                            UserStore <ApplicationUser>(new ApplicationDbContext()));
            string userName   = Context.User.Identity.GetUserName();
            int    employeeid = 0;

            if (!string.IsNullOrEmpty(userName))
            {
                employeeid = userManager.Get_CurrentEmployeeIDFromUserName(userName);
            }
            MessageUserControl.TryRun(() =>
            {
                Sale sale        = new Sale();
                sale.SaleDate    = DateTime.Now;
                sale.PaymentType = PaymentDDL.SelectedValue;
                sale.EmployeeID  = employeeid;
                sale.TaxAmount   = decimal.Parse(TaxLabel.Text);
                sale.SubTotal    = decimal.Parse(SubTotalLabel.Text);
                if (!string.IsNullOrEmpty(CouponIDLabel.Text))
                {
                    sale.CouponID = int.Parse(CouponIDLabel.Text);
                }

                ShoppingCartController sysmgr = new ShoppingCartController();
                ShoppingCart cart             = sysmgr.Get_ShoppingCartByEmployeeID(employeeid);
                SalesDetailController sysmg2  = new SalesDetailController();
                sysmg2.PlaceOrder(sale, cart);
            }, "Place Order", "Order successfully placed.");
            ProductSelectionListView.DataBind();
            CartListView.DataBind();
            CheckoutGridView.DataBind();
            SubTotalLabel.Text       = "";
            TaxLabel.Text            = "";
            Label3.Text              = "";
            DiscountLabel.Text       = "";
            TotalLabel.Text          = "";
            MainView.ActiveViewIndex = 2;
        }
Exemple #4
0
 private void emptyCartButton_Click(object sender, EventArgs e)
 {
     Customer.Cart.EmptyCart();
     CartListView.Clear();
 }