public ActionResult Create(int Itemid) { if (ModelState.IsValid) { Shoppingcart Cart = new Shoppingcart(); var userId = db.Users.Find(User.Identity.GetUserId()); var exshopping = db.ShoppingCarts.Where(s => s.CustomerId == userId.Id && s.Item.Id == Itemid).ToList(); if (exshopping.Count == 0) { Cart.CreationDate = System.DateTime.Now; Cart.Count = 1; Cart.CustomerId = userId.Id; Cart.ItemId = Itemid; db.ShoppingCarts.Add(Cart); db.SaveChanges(); return(RedirectToAction("index", "Home")); } foreach (var items in exshopping) { items.Count++; db.Entry(items).Property("Count").IsModified = true; } db.SaveChanges(); } return(RedirectToAction("index", "Home")); }
public ActionResult DeleteConfirmed(int id) { Shoppingcart shoppingCart = db.ShoppingCarts.Find(id); db.ShoppingCarts.Remove(shoppingCart); db.SaveChanges(); return(RedirectToAction("Index")); }
/// <summary> /// 从资源库获取当前购物车,如果未找到则创建新的 /// </summary> /// <param name="cashier"></param> /// <returns></returns> public Shoppingcart GetCurrentShoppingcartOrCreate(UserCredentials cashier) { var shoppingcart = shoppingcarts.FirstOrDefault(o => !o.IsSuspended); if (shoppingcart == null) { shoppingcart = new Shoppingcart(cashier); shoppingcarts.Add(shoppingcart); } return(shoppingcart); }
//you have got a menu of pizza types. //a user can choose from 2 type of pizza dought. //a user can add some additional ingredients of their order. // a user can choose a custom pizza with four ingredients. // a user can order more than one pizza. // after the user confirms their order, the total is displayed. static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = ConsoleColor.DarkBlue; Warehouse currentlyInStock = new Warehouse(); //Create a Shopping Cart object Shoppingcart shoppingCart = new Shoppingcart(); //Display the warehouse content currentlyInStock.PrintInStock(); AddItemsToShoppingCart(currentlyInStock, shoppingCart); while (true) { Console.WriteLine("Add/Add your extra/Choose your dough/Remove/Confirm"); string userInput = Console.ReadLine().ToLower(); if (userInput == "add") { AddItemsToShoppingCart(currentlyInStock, shoppingCart); } else if (userInput == "add your extra") { Console.WriteLine("Enter the id of the extra(id:5-10) to add to the pizza."); int productID = int.Parse(Console.ReadLine()); Console.WriteLine("Enter the number of extras to add to the shopping cart: "); int quantity = int.Parse(Console.ReadLine()); Article articleToAdd = currentlyInStock.GetFromStock(productID); shoppingCart.AddToShoppingCart(articleToAdd, quantity); shoppingCart.PrintShoppingCart(); } else if (userInput == "choose your dough") { Console.WriteLine("Now choose your pizza dough: basic(id 11), super(id 12):"); int productID = int.Parse(Console.ReadLine()); Article articleToAdd = currentlyInStock.GetFromStock(productID); shoppingCart.AddToShoppingCart(articleToAdd, 1); shoppingCart.PrintShoppingCart(); } else if (userInput == "remove") { Console.WriteLine("Enter the id of the pizza to remove from the shopping cart: "); int itemIdToremove = int.Parse(Console.ReadLine()); shoppingCart.RemoveFromShoppingCart(itemIdToremove); } else if (userInput == "confirm") { shoppingCart.PrintTotal(); Console.WriteLine($"Total: {shoppingCart.Total} euros. Thank you for generous tips!"); break; } } }
public void Update(string Item_Number, int user_id) { Shoppingcart updatewishlist = new Shoppingcart() { Item_Number = Item_Number, user_id = user_id }; _context.Update(updatewishlist); _context.Entry(updatewishlist); _context.SaveChanges(); }
public static void AddItemsToShoppingCart(Warehouse currentlyInStock, Shoppingcart shoppingCart) { Console.WriteLine("Enter the id of the pizza(id 1-5) to add it to the shopping cart: "); int productID = int.Parse(Console.ReadLine()); Console.WriteLine("Enter the number of items to add to the shopping cart: "); int quantity = int.Parse(Console.ReadLine()); Article articleToAdd = currentlyInStock.GetFromStock(productID); shoppingCart.AddToShoppingCart(articleToAdd, quantity); shoppingCart.PrintShoppingCart(); }
public ActionResult Edit([Bind(Include = "Id,Itemid,Count,CreationDate")] Shoppingcart shoppingCart) { if (ModelState.IsValid) { var userId = db.Users.Find(User.Identity.GetUserId()); shoppingCart.CustomerId = userId.Id; db.Entry(shoppingCart).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Itemid = new SelectList(db.Items, "Id", "Name", shoppingCart.ItemId); return(View(shoppingCart)); }
public void CreateShoppingcart(string Item_Number, int user_id, int amount, string price) { Shoppingcart newwishlist = new Shoppingcart() { Item_Number = Item_Number, user_id = user_id, amount = amount, price = price }; _context.Shoppingcarts.Add(newwishlist); _context.SaveChanges(); }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Shoppingcart shoppingCart = db.ShoppingCarts.Find(id); if (shoppingCart == null) { return(HttpNotFound()); } return(View(shoppingCart)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Shoppingcart shoppingCart = db.ShoppingCarts.Find(id); if (shoppingCart == null) { return(HttpNotFound()); } ViewBag.Itemid = new SelectList(db.Items, "Id", "Name", shoppingCart.ItemId); return(View(shoppingCart)); }
public int insert(Shoppingcart Shoppc) { string sql = "insert into Shoppingcart values(@ShoppingID,@UserID,@ProductID,@CreateTime,@UnitPrices,@Allprices,@Quality)"; SqlParameter[] sp = new SqlParameter[] { new SqlParameter("@ShoppingID", Shoppc.ShoppingID), new SqlParameter("@UserID", Shoppc.UserID), new SqlParameter("@ProductID", Shoppc.ProductID), new SqlParameter("@CreateTime", Shoppc.CreateTime), new SqlParameter("@UnitPrices", Shoppc.UnitPrices), new SqlParameter("@Allprices", Shoppc.Allprices), new SqlParameter("@Quality", Shoppc.Quality), }; return (DBHelper.GetExcuteNonQuery(sql, sp)); }
public int insert(Shoppingcart Shoppc) { return(IShoppingcart.insert(Shoppc)); }