public void StartUp() { Console.WriteLine("Please choose an action and a product:" + " Apple/Book/Toy/Show Cart/END"); string[] commands = Console.ReadLine().Split(' ').ToArray(); do { if (commands[0] == "Add") { if (commands[1] == "Apple") { cart.Add(apple); } if (commands[1] == "Book") { cart.Add(book); } if (commands[1] == "Toy") { cart.Add(toy); } } if (commands[0] == "Remove") { if (commands[1] == "Apple") { cart.Remove(apple); } if (commands[1] == "Book") { cart.Remove(book); } if (commands[1] == "Toy") { cart.Remove(toy); } } if (commands[0] == "Show Cart") { cart.Print(); } commands = Console.ReadLine().Split(' ').ToArray(); }while (commands[0] == "END"); Console.WriteLine("-------------------------------- "); Console.WriteLine("Thank you for choosing us!"); Console.WriteLine("-------------------------------- "); }
public void Can_AddCan_Remove_Line_Quantity_For_Existing_Lines() { // Arrange - create some test products var p1 = new Product { ProductId = 1, Name = "P1" }; var p2 = new Product { ProductId = 2, Name = "P2" }; var p3 = new Product { ProductId = 3, Name = "P3" }; // Arrange - create a new cart var target = new Cart(); // Act target.AddItem(p1, 1); target.AddItem(p2, 3); target.AddItem(p3, 5); target.AddItem(p2, 1); target.Remove(p2); // Assert Assert.Equal(0, target.Lines.Count(c => c.Product == p2)); Assert.Equal(2, target.Lines.Count()); }
public void AddToCart() { CartItemModel existingItem = Cart.FirstOrDefault(x => x.Product == SelectedProduct); if (existingItem != null) { existingItem.QuantityInCart += ItemQuantity; //HACK - No the best way to refresh cart display Cart.Remove(existingItem); Cart.Add(existingItem); } else { CartItemModel item = new CartItemModel { Product = SelectedProduct, QuantityInCart = ItemQuantity }; Cart.Add(item); } SelectedProduct.QuantitiyInStock -= ItemQuantity; ItemQuantity = 1; NotifyOfPropertyChange(() => SubTotal); NotifyOfPropertyChange(() => Tax); NotifyOfPropertyChange(() => Total); NotifyOfPropertyChange(() => CanCheckOut); }
public JsonResult RemoveFromCart(string id) { Cart cart = (Cart)Session["cart"]; cart.Remove(id); return(Json(cart.numberOfItems(), JsonRequestBehavior.AllowGet)); }
public void changeQty() { TextBox qtyTextBox; HiddenField productIDHiddenField; CheckBox removeCheckBox; int qty = 0; int ProductID = 0; foreach (RepeaterItem row in ShoppingCartRepeater.Items) { qtyTextBox = (TextBox)row.FindControl("qtyTextBox"); productIDHiddenField = (HiddenField)row.FindControl("ProductIDHiddenField"); removeCheckBox = (CheckBox)row.FindControl("removeCheckBox"); if (int.TryParse(WebUtility.InputText(qtyTextBox.Text, 10), out qty) && int.TryParse(WebUtility.InputText(productIDHiddenField.Value, 10), out ProductID)) { if (removeCheckBox.Checked || qty < 1) { shoppingCart.Remove(ProductID); } else if (qty > 0) { shoppingCart.SetQuantity(ProductID, qty); } } } }
protected void Button1_Click(object sender, EventArgs e) { Button btn = (Button)sender; GridViewRow gvr = (GridViewRow)btn.NamingContainer; Cart myCart; myCart = (Cart)Session["myCart"]; myCart.Remove(gvr.RowIndex); GridView1.DataSource = myCart.Items; GridView1.DataBind(); lblMessage.Text = ""; lblTotalPrice.Text = myCart.Total.ToString(); if ((Convert.ToInt32(lblTotalPrice.Text)) == 0) { lblMessage.Text = "Кошничката е празна"; ImageButton1.Visible = false; ImageButton2.Visible = false; lblDenar.Visible = false; lblIsprazni.Visible = false; lblKupi.Visible = false; lblTotal.Visible = false; lblTotalPrice.Visible = false; Session["myCart"] = null; } else { ImageButton1.Visible = true; ImageButton2.Visible = true; lblDenar.Visible = true; lblIsprazni.Visible = true; lblKupi.Visible = true; lblTotal.Visible = true; lblTotalPrice.Visible = true; } }
public void RemoveItemsOnItemsInCart() { // Add var TestCart = new Cart(); var TestCartItem1 = new OrderItems(); TestCartItem1.OrderId = Guid.Parse("4dfce571-6d27-4bb1-92b1-120507eae0ce"); TestCartItem1.ProductId = Guid.Parse("6e1a67cb-8493-4145-bcfa-2ab5ec30e9df"); TestCartItem1.Quantity = 25; var TestCartItem2 = new OrderItems(); TestCartItem2.OrderId = Guid.Parse("589479e2-9c27-48cc-a49b-c61f4e74acc3"); TestCartItem2.ProductId = Guid.Parse("fc3d54a1-aee2-4a0f-b337-fa1d0a8b0a5c"); TestCartItem2.Quantity = 25; TestCart.Products.Add(TestCartItem1); TestCart.Products.Add(TestCartItem2); bool expected = true; // Arrange bool actual = TestCart.Remove(Guid.Parse("fc3d54a1-aee2-4a0f-b337-fa1d0a8b0a5c")); // Assert Assert.Equal(expected, actual); }
private void Remove_Product_from_Cart_Click(object sender, RoutedEventArgs e) { if (MessageBox.Show("Are You Sure Want to Delete This Product?", "Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { try { if (ltbxCart.SelectedItem != null) { foreach (Product product in cart) { if (ltbxCart.SelectedItem == product) { cart.Remove(product); break; } } ltbxCart.Items.Remove(ltbxCart.SelectedItem); UpdateLists(); } MessageBox.Show("Product has been delete from list", "Caution", MessageBoxButton.OK); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public void AddToCart() { CartItemDisplayModel existingItem = Cart.FirstOrDefault(x => x.Product == SelectedProduct); if (existingItem != null) { existingItem.QuantityInCart += ItemQuantity; // Hack - there should be a better way of refreshing the cart display Cart.Remove(existingItem); Cart.Add(existingItem); } else { CartItemDisplayModel item = new CartItemDisplayModel { Product = SelectedProduct, QuantityInCart = ItemQuantity }; Cart.Add(item); } SelectedProduct.QuantityInStock -= ItemQuantity; ItemQuantity = 1; NotifyOfPropertyChange(() => SubTotal); NotifyOfPropertyChange(() => Tax); NotifyOfPropertyChange(() => Total); NotifyOfPropertyChange(() => CanCheckout); }
public void AddToCart() { CartItemDisplayModel existingItem = Cart.FirstOrDefault(x => x.Product == SelectedProduct); if (existingItem != null) { existingItem.QuantityInCart += quantity; Cart.Remove(existingItem); Cart.Add(existingItem); } else { var cartItem = new CartItemDisplayModel { Product = SelectedProduct, QuantityInCart = quantity }; Cart.Add(cartItem); } SelectedProduct.QuantityInStock -= quantity; ItemQuantity = 1.ToString(); NotifyOfPropertyChange(() => SubTotal); NotifyOfPropertyChange(() => Tax); NotifyOfPropertyChange(() => Total); NotifyOfPropertyChange(() => CanCheckOut); }
public void AddToCart() { // find exsiting objecct in cart CartItemModel existingItem = Cart.FirstOrDefault(x => x.Product == SelectedProduct); if (existingItem != null) { existingItem.QuantityInCart += ItemQuantity; Cart.Remove(existingItem); Cart.Add(existingItem); } else { CartItemModel item = new CartItemModel { Product = SelectedProduct, QuantityInCart = ItemQuantity }; Cart.Add(item); } // update the quantity in DB SelectedProduct.QuantityInStock -= ItemQuantity; ItemQuantity = 1; // reset the ItemQuantity NotifyOfPropertyChange(() => SubTotal); NotifyOfPropertyChange(() => Tax); NotifyOfPropertyChange(() => Total); }
public bool RemoveItem([FromBody] string toyId) { // get cart in session Cart cart = null; List <KeyValuePair <Toy, int> > toyList = null; var cartJson = HttpContext.Session.GetString("CART"); if (string.IsNullOrEmpty(cartJson)) { return(false); } toyList = JsonConvert.DeserializeObject <List <KeyValuePair <Toy, int> > >(cartJson); cart = new Cart(toyList.ToDictionary(item => item.Key, item => item.Value)); cart.Remove(new Toy { _id = toyId }); if (cart.Count == 0) { HttpContext.Session.Remove("CART"); } else { // add cart to session toyList = cart.ToList(); cartJson = JsonConvert.SerializeObject(toyList); HttpContext.Session.SetString("CART", cartJson); } return(true); }
public async void RemoveFromCart() { var handler = new WebRequestHandler(); await handler.Post("http://localhost/ShoppingCartAPI/ShoppingCart/DeleteItem", SelectedCartItem); if (SelectedCartItem == null) { return; } if (Cart.Any(i => i.Id.Equals(SelectedCartItem.Id))) { var cartItem = Cart.FirstOrDefault(i => i.Id.Equals(SelectedCartItem.Id)); if (cartItem.Units > 1) { Cart.FirstOrDefault(i => i.Id.Equals(cartItem.Id)).decUnits(); } else { Cart.Remove(cartItem); } } SelectedCartItem = null; NotifyPropertyChanged("SelectedCartItem"); NotifyPropertyChanged("Total"); NotifyPropertyChanged("Subtotal"); NotifyPropertyChanged("Taxes"); }
public void RemoveProductWhenObjectDoesnotExistsIn() { //Arrange var targetGood = new Good() { Price = 12.2m, Supplier = new Supplier() { Name = "Maxim" } }; var map = new Dictionary <string, IProduct>(new List <KeyValuePair <string, IProduct> > { new KeyValuePair <string, IProduct>("cart_list_1", new Good()), }); var expected = map; var context = FakeHttpContext.NewFakeHttpContext(); context.SetupProperty(e => e.Session, FakeHttpContext.FakeSession(map).Object); var cart = new Cart(context.Object); //Actual cart.Remove(targetGood); //Assert NAssert.AreEqual(expected, map); }
public IActionResult Remove(string id) { var item = cart.GetCartItemByID(id); cart.Remove(item); return(RedirectToAction("Index")); }
public void AddToCart() { CartItemModel existingItem = Cart.FirstOrDefault(x => x.Product == SelectedProduct); if (existingItem != null) { existingItem.QuantityInCart += ItemQuantity; Cart.Remove(existingItem); Cart.Add(existingItem); } else { CartItemModel item = new CartItemModel { Product = SelectedProduct, QuantityInCart = ItemQuantity }; Cart.Add(item); } SelectedProduct.QuantityInStock -= ItemQuantity; ItemQuantity = 1; NotifyOfPropertyChange(() => SubTotal); NotifyOfPropertyChange(() => Cart); }
private void RemoveFromCart(string sku) { if (Cart.ContainsKey(sku)) { Cart.Remove(sku); } }
public void RemoveFromCart() { var ExistingProduct = Products.FirstOrDefault(x => x == SelectedCartItem.Product); if (ExistingProduct == null) { Products.Add(SelectedCartItem.Product); } SelectedCartItem.Product.QuantityInStock += 1; if (SelectedCartItem.QuantityInCart > 1) { SelectedCartItem.QuantityInCart -= 1; } else { Cart.Remove(SelectedCartItem); } NotifyOfPropertyChange(() => SubTotal); NotifyOfPropertyChange(() => Tax); NotifyOfPropertyChange(() => Total); NotifyOfPropertyChange(() => CanCheckOut); NotifyOfPropertyChange(() => CanRemoveFromCart); }
public RedirectResult Remove(long id) { Cart obj = new Cart(); ItemCart item = new ItemCart(); item.Product = new Product(); item.Product = _productService.Get((int)id); var strResponse = HttpContext.Session.GetString(SessionCart); obj.Itens = new List <ItemCart>(); if (!string.IsNullOrEmpty(strResponse)) { var cart = JsonConvert.DeserializeObject <Cart>(strResponse); obj = cart; } obj.Remove(obj, item); var str = JsonConvert.SerializeObject(obj); HttpContext.Session.SetString(SessionCart, str); return(Redirect("/Order/Cart")); }
public void DeleteProduct() { Cart.Remove(SelectedProduct); NotifyOfPropertyChange(() => Cart); NotifyOfPropertyChange(() => TotalSubTotal); NotifyOfPropertyChange(() => TotalTax); NotifyOfPropertyChange(() => TotalTotal); }
private void RemoveAlbumsFromCart(IEnumerable <Guid> productsToRemove, Cart cart) { foreach ( var product in productsToRemove.Select(productId => _albumRepository.FindBy(productId)).Where(product => product != null)) { cart.Remove(product); } }
public void RemovingNonExistingItemFromCart_Throws_ItemNotFoundException(int productId, int quantity) { var product = _inventory[productId]; Action action = () => _cart.Remove(product, Quantity.Is(quantity)); Assert.Throws <ItemNotFoundException>(action); }
public void Remove(int knifeId) { var knife = _unitOfWork.KnifeRepository.Get(x => x.Id == knifeId); var mapped = _mapper.Map <Knife, KnifeDTO>(knife); _cart.Remove(mapped); BasketChanged?.Invoke(this, new EventArgs()); }
public ActionResult Delete(int id) { Cart cart = (Cart)Session["Cart"]; cart.Remove(id); Session.Add("Cart", cart); return(RedirectToAction("Index", "ShoppingCart")); }
private void listBox2_DoubleClick(object sender, EventArgs e) { if (listBox2.SelectedItem is Product product) { cart.Remove(product); listBox2.Items.Remove(product); UpdateLists(); } }
public Task <Unit> Handle(RemoveFoodCommand request, CancellationToken cancellationToken) { Cart cart = Cart.FromByteArray(request.Session.Get("Cart")); cart.Remove(request.FoodId); cart.Save(request.Session); return(Unit.Task); }
public void Remove(Product product) { var cartItem = _cart.FirstOrDefault(ci => ci.Product.Sku == product.Sku); if (cartItem != null) { _cart.Remove(cartItem); } }
public IActionResult RemoveCart(int id) { Cart cart = GetCart(); var product = productService.GetProductById(id); cart.Remove(product); SaveCart(cart); return(Json("OK")); }
public ActionResult RemoveFromCart(Cart cart, int PhoneId) { Phone p = db.Phones.FirstOrDefault(a => a.PhoneId == PhoneId); if (p != null) { cart.Remove(p); } return(RedirectToAction("Cart")); }
public ActionResult RemoveItem(string itemId) { if (!string.IsNullOrEmpty(itemId)) { CartController cartController = new CartController(); Cart myCart = cartController.GetCart(true); myCart.Remove(itemId); } return(Redirect("ShoppingCart")); }
public void Generate(ChartResultParameter par) { DateTime begin = DateTime.Now; HtmlTemplate index = new HtmlTemplate("index"); string articlesString = "", cancellationsString = "", depositsString = ""; string usersString = ""; double sum = 0.0; result.Sales.Sort(par.SortOrder); result.Cancellations.Sort(par.SortOrder); index.Insert("datetime", DateTime.Now.ToString()); index.Insert("version", Administration.Properties.Resources.Version); #region information index.Insert("profile", chart.Profile.Name); foreach (User u in chart.Users) usersString += u.Username + "<br />\r\n"; usersString.Remove(usersString.Length - 8); index.Insert("user", usersString); index.Insert("cancellationsInvolved", par.InvolveCancellation ? "ja" : "nein"); index.Insert("deletedArticlesShown", par.ShowDeletedArticles ? "ja" : "nein"); index.Insert("sortedBy", par.SortOrder.ToString()); #endregion #region articles HtmlTemplate articles = new HtmlTemplate("articlecollection"); articles.Insert("header", "Artikel"); foreach (ArticleCount ac in result.Sales.Container) { if (!par.ShowDeletedArticles && ac.Article.IsDeleted) continue; if (!par.ShowUnsoldArticles && ac.Count < 1) continue; HtmlTemplate tpl = new HtmlTemplate("article"); tpl.Insert("name", ac.Article.Name); tpl.Insert("price", string.Format("{0:0.00 €}", ac.Article.Price)); tpl.Insert("count", par.InvolveCancellation ? (ac.Count - result.Cancellations[ac.Article].Count).ToString() : ac.Count.ToString()); tpl.Insert("sum", par.InvolveCancellation ? string.Format("{0:0.00 €}", ac.Article.Price * (ac.Count - result.Cancellations[ac.Article].Count)) : string.Format("{0:0.00 €}", ac.Article.Price * ac.Count)); articlesString += tpl.Get(); } articles.Insert("articles", articlesString); articles.Insert("articlescount", par.InvolveCancellation ? (result.Sales.Count - result.Cancellations.Count).ToString() : result.Sales.Count.ToString()); sum = par.InvolveCancellation ? (result.Sales.Amount - result.Cancellations.Amount) : result.Sales.Amount; articles.Insert("articlessum", string.Format("{0:0.00 €}", sum)); index.Insert("sales", articles.Get()); #endregion #region deposits double depositSum = 0.0; int depositCount = 0; List<ArticleCount> deps = (from d in result.Sales.Container where d.Article.Deposit.DepositID != -1 select d as ArticleCount).ToList(); List<ArticleCount> depcancs = (from d in result.Cancellations.Container where d.Article.Deposit.DepositID != -1 select d as ArticleCount).ToList(); Cart depresult = new Cart(); foreach (ArticleCount d in deps) depresult.Add(d); if (par.InvolveCancellation) // remove cancelled deposites foreach (ArticleCount d in depcancs) depresult.Remove(d); // add returned deposites which are not children of depresult (never bought it, but returned it) List<DepositReturn> unbought = (from d in result.DepositReturns where (from a in depresult.Container select a.Article.Deposit).ToList<Deposit>().Contains(d.Deposit) == false select d).ToList(); foreach (DepositReturn d in unbought) { int count = d.Count; HtmlTemplate tpl = new HtmlTemplate("article"); tpl.Insert("name", d.Deposit.Name); tpl.Insert("price", string.Format("{0:0.00 €}", d.Deposit.Amount)); tpl.Insert("count", count.ToString()); tpl.Insert("sum", string.Format("{0:0.00 €}", count * d.Deposit.Amount)); depositSum -= count * d.Deposit.Amount; depositCount -= count; depositsString += tpl.Get(); } // enumerate deposit objects foreach (ArticleCount d in depresult.Container) { int count = d.Count; // subtract returned deposites foreach (DepositReturn dr in (from ret in result.DepositReturns where ret.Deposit.DepositID == d.Article.Deposit.DepositID select ret).ToList()) { count -= dr.Count; } HtmlTemplate tpl = new HtmlTemplate("article"); tpl.Insert("name", d.Article.Deposit.Name); tpl.Insert("price", string.Format("{0:0.00 €}", d.Article.Deposit.Amount)); tpl.Insert("count", count.ToString()); tpl.Insert("sum", string.Format("{0:0.00 €}", count * d.Article.Deposit.Amount)); depositSum += count * d.Article.Deposit.Amount; depositCount += count; depositsString += tpl.Get(); } if (par.ShowDeposits) { HtmlTemplate deposits = new HtmlTemplate("articlecollection"); deposits.Insert("header", "Pfänder"); deposits.Insert("articles", depositsString); deposits.Insert("articlescount", depositCount.ToString()); deposits.Insert("articlessum", string.Format("{0:0.00 €}", depositSum)); index.Insert("deposits", deposits.Get()); } else index.Insert("deposits", ""); #endregion #region cancellations if (par.ShowCancellation) { HtmlTemplate cancellations = new HtmlTemplate("articlecollection"); cancellations.Insert("header", "Stornos"); foreach (ArticleCount ac in result.Cancellations.Container) { HtmlTemplate tpl = new HtmlTemplate("article"); tpl.Insert("name", ac.Article.Name); tpl.Insert("price", string.Format("{0:0.00 €}", ac.Article.Price)); tpl.Insert("count", ac.Count.ToString()); tpl.Insert("sum", string.Format("{0:0.00 €}", ac.Article.Price * ac.Count)); cancellationsString += tpl.Get(); } cancellations.Insert("articles", cancellationsString); cancellations.Insert("articlescount", result.Cancellations.Count.ToString()); cancellations.Insert("articlessum", string.Format("{0:0.00 €}", result.Cancellations.Amount)); index.Insert("cancellations", cancellations.Get()); } else index.Insert("cancellations", ""); #endregion #region staff if (par.ShowCalculation) { HtmlTemplate calculation = new HtmlTemplate("staffcalculation"); calculation.Insert("header", "Abrechnung"); calculation.Insert("sum", string.Format("{0:0.00 €}", sum)); calculation.Insert("commissionpercentage", string.Format("{0:0.0 %}", par.Provision / 100)); calculation.Insert("commissionamount", string.Format("{0:0.00 €}", sum * par.Provision / 100)); calculation.Insert("benefit", string.Format("{0:0.00 €}", par.FreeAmount)); calculation.Insert("depositsum", string.Format("{0:0.00 €}", depositSum)); calculation.Insert("summary", string.Format("{0:0.00 €}", sum + depositSum - (sum * par.Provision / 100) - par.FreeAmount)); index.Insert("staff", calculation.Get()); } else index.Insert("staff", ""); #endregion index.Insert("creationduration", (result.CreationBegin - result.CreationEnd).ToString()); index.Insert("writingduration", (begin - DateTime.Now).ToString()); this.output = index.Get(); }
private void RemoveAlbumsFromCart(IEnumerable<Guid> productsToRemove, Cart cart) { foreach ( var product in productsToRemove.Select(productId => _albumRepository.FindBy(productId)).Where(product => product != null)) { cart.Remove(product); } }