public ActionResult CartSummary() { var cart = UserShoppingCart.GetCart(this.HttpContext); ViewData["CartCount"] = cart.GetCount(); return(PartialView("CartSummary")); }
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)); } }
// // 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")); }
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; }
// // 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)); }
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; }
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); }
// // 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("")); }