コード例 #1
0
        public ActionResult CartSummary()
        {
            var cart = UserShoppingCart.GetCart(this.HttpContext);

            ViewData["CartCount"] = cart.GetCount();
            return(PartialView("CartSummary"));
        }
コード例 #2
0
        public ActionResult Confirmation(ViewModels.CartViewModel viewModel)
        {
            var invoice = new invoice_table();

            TryUpdateModel(invoice);

            try
            {
                // Get user num
                int usernum = 0;
                foreach (var users in storeDB.users_table)
                {
                    if (users.username == HttpContext.User.Identity.Name)
                    {
                        usernum = users.user_num;
                    }
                }

                invoice.user_num       = usernum;
                invoice.invoice_date   = DateTime.Now;
                invoice.invoice_filled = "Pending";

                storeDB.invoice_table.Add(invoice);
                storeDB.SaveChanges();

                var cart = UserShoppingCart.GetCart(this.HttpContext);
                cart.CreateOrder(invoice);

                List <parts_table> tempPartsTable = new List <parts_table>();

                // Subtract stock from how much the user ordered
                foreach (var orderItem in storeDB.orders_table)
                {
                    if (orderItem.invoice_num == invoice.invoice_num)
                    {
                        var currentPart = storeDB.parts_table.FirstOrDefault(part_table => part_table.part_number == orderItem.part_num);
                        currentPart.part_stock = currentPart.part_stock - orderItem.quantity;
                        tempPartsTable.Add(currentPart);
                    }
                }

                // Run through and modify the stock of parts
                foreach (parts_table partItem in tempPartsTable)
                {
                    storeDB.Entry(partItem).State = System.Data.EntityState.Modified;
                    storeDB.SaveChanges();
                }

                return(RedirectToAction("Finished", new { id = invoice.invoice_num }));
            }
            catch (Exception)
            {
                return(View(viewModel));
            }
        }
コード例 #3
0
        //
        // GET: /Store/AddToCart/5
        public ActionResult AddToCart(int id)
        {
            // Retrieve the part from the database
            var addedPart = storeDB.parts_table.FirstOrDefault(parts_table => parts_table.part_number == id);

            // Add it to the shopping cart
            var cart = UserShoppingCart.GetCart(this.HttpContext);

            cart.AddToCart(addedPart);

            // Go back to the main store page for more shopping
            return(RedirectToAction("Index"));
        }
コード例 #4
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        // Set current user prefs.
        UserShoppingCart cart =
            (UserShoppingCart)Session["UserShoppingCartInfo"];

        cart.dateOfPickUp               = myCalendar.SelectedDate;
        cart.desiredCar                 = txtCarMake.Text;
        cart.desiredCarColor            = txtCarColor.Text;
        cart.downPayment                = float.Parse(txtDownPayment.Text);
        cart.isLeasing                  = chkIsLeasing.Checked;
        lblUserInfo.Text                = cart.ToString();
        Session["UserShoppingCartInfo"] = cart;
    }
コード例 #5
0
        //
        // GET: /ShoppingCart/
        public ActionResult Index()
        {
            var cart = UserShoppingCart.GetCart(this.HttpContext);
            var part = storeDB.parts_table.ToList();

            // Set up our ViewModel
            var viewModel = new CartViewModel
            {
                CartItems = cart.GetCartItems(),
                PartItems = part,
                CartTotal = cart.GetTotal()
            };

            // Return the view
            return(View(viewModel));
        }
コード例 #6
0
    protected void submitButton_Click(object sender, EventArgs e)
    {
        // Установить предпочтения текущего пользователя
        UserShoppingCart cart = Session["UserShoppingCartInfo"] as UserShoppingCart;

        if (cart == null)
        {
            return;
        }
        cart.DateOfPickUp               = calendar.SelectedDate;
        cart.DesiredCar                 = whichMakeTextBox.Text;
        cart.DesiredCarColor            = whichColorTextBox.Text;
        cart.DownPayment                = float.Parse(downPaymentTextBox.Text);
        cart.IsLeasing                  = leaseCheckBox.Checked;
        userInfoLabel.Text              = cart.ToString();
        Session["UserShoppingCartInfo"] = cart;
    }
コード例 #7
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        // Set current user prefs.
        UserShoppingCart u =
            (UserShoppingCart)Session["UserShoppingCartInfo"];

        u.dateOfPickUp    = myCalendar.SelectedDate;
        u.desiredCar      = txtCarMake.Text;
        u.desiredCarColor = txtCarColor.Text;
        u.downPayment     = float.Parse(txtDownPayment.Text);
        u.isLeasing       = chkIsLeasing.Checked;
        lblUserInfo.Text  = u.ToString();
        Session["UserShoppingCartInfo"] = u;

        lblUserID.Text = string.Format("Here is your ID: {0}",
                                       Session.SessionID);
    }
コード例 #8
0
        //
        // AJAX: /ShoppingCart/RemoveFromCart/5
        public ActionResult RemoveFromCart(int id)
        {
            // Remove the item from the cart
            var cart = UserShoppingCart.GetCart(this.HttpContext);

            // Remove from cart
            int itemCount = cart.RemoveFromCart(id);

            // Display the confirmation message
            var results = new RemoveCartViewModel
            {
                Message = Server.HtmlEncode("testName1") +
                          " has been removed from your shopping cart.",
                CartTotal = cart.GetTotal(),
                CartCount = cart.GetCount(),
                ItemCount = itemCount,
                DeleteId  = id
            };

            //return Json(results, JsonRequestBehavior.AllowGet);
            return(RedirectToAction(""));
        }