public void Checkout_Has_BasketInfo() { ICheckout co = new Checkout(new PricingEngine()); BasketInfo info = co.GetBasketInfo(); Assert.IsNotNull(info); }
public void If_Scan_A_Then_BasketInfo_Has_A_Once() { ICheckout co = new Checkout(new PricingEngine()); co.Scan("A"); BasketInfo info = co.GetBasketInfo(); int countA = info.GetCount("A"); int expectedCountA = 1; Assert.AreEqual(expectedCountA, countA); }
public ActionResult BasketInfo() { var basket = _service.GetBasket(User.Identity.Name); var count = basket?.OrderDetails?.Sum(x => x.Quantity) ?? 0; var sum = basket?.OrderDetails?.Sum(x => x.Price) ?? 0; var info = new BasketInfo { Count = count, Summ = sum }; return(PartialView("BasketInfo", info)); }
internal List <BasketInfo> GetBasket(int readerId) { DataTable table = dbWrapper.GetBasket(readerId); List <BasketInfo> basket = new List <BasketInfo>(); foreach (DataRow row in table.Rows) { BasketInfo bi = new BasketInfo(); bi.BookId = row["BookId"].ToString(); bi.ID = (int)row["ID"]; bi.ReaderId = (int)row["ReaderId"]; bi.PutDate = (DateTime)row["PutDate"]; bi.AlligatBookId = row["AlligatBookId"].ToString(); basket.Add(bi); } return(basket); }
// Add to basket product with productid public ActionResult AddToBasket(string ProductID) { // If haven't login => login and come back if (Session["UserID"] == null) { return(RedirectToAction("Login", "Users", new { @returnUrl = Request.Url.OriginalString })); } string userid = Session["UserID"].ToString(); var basket = DataProvider.Instance.DataBase.Baskets.Where(x => x.IdCustomer == userid).SingleOrDefault(); if (basket == null) { basket = new Basket() { Id = Guid.NewGuid().ToString(), IdCustomer = userid, }; DataProvider.Instance.DataBase.Baskets.Add(basket); DataProvider.Instance.DataBase.SaveChanges(); } var bi = DataProvider.Instance.DataBase.BasketInfoes.Where(x => x.IdProduct == ProductID && x.IdBasket == basket.Id).SingleOrDefault(); if (bi == null) { bi = new BasketInfo() { Id = Guid.NewGuid().ToString(), IdBasket = basket.Id, IdProduct = ProductID, Count = 1, }; DataProvider.Instance.DataBase.BasketInfoes.Add(bi); } else { bi.Count++; } DataProvider.Instance.DataBase.SaveChanges(); return(RedirectToAction("ShowProduct", "Home", new { @ProductID = ProductID })); }
private void updateBooksList() { BasketInfo bi = BookServiceClient.instance.Service.getUserBasket(BookServiceClient.instance.user); dataGridView1.Rows.Clear(); foreach (BasketItem b in bi.items) { int ni = dataGridView1.Rows.Add(); DataGridViewRow r = dataGridView1.Rows[ni]; r.Tag = b; r.Cells["name"].Value = b.book.name; r.Cells["count"].Value = b.count; r.Cells["price"].Value = b.book.price; r.Cells["price_all"].Value = b.book.price * b.count; r.Cells["genre"].Value = b.book.genre.name; string authors = ""; foreach (Author a in b.book.authors) { authors += (authors.Length == 0 ? "" : "; ") + a.name; } r.Cells["authors"].Value = authors; } label1.Text = bi.calcInfo.ToString(); }