static void Main(string[] args) { ShoppingService shoppingService = new ShoppingService(); //Product apple = new Product { Id = 1, Name = "apple", Price = 1m }; //ShoppingCart cart = new ShoppingCart(); //cart.ShoppingItems.Add(new ShoppingItem { ProductId = 1, Count = 1 }); //Receipt receipt = new Receipt(); //receipt.ShoppingItems.AddRange(cart.ShoppingItems); //MockShoppingCartRepository mockShoppingCartRepository = new MockShoppingCartRepository(); //var shoppingCart1 = mockShoppingCartRepository.Create(); //var shoppingCart2 = mockShoppingCartRepository.Create(); var allproduct = shoppingService.GetAllProducts(); var cart = shoppingService.CreateShoppingCart(); shoppingService.BuyProduct(cart.Id, 1, 2); Console.ReadLine(); }
private void button2_Click(object sender, EventArgs e) { if (_cart == null) { _cart = _shoppingService.CreateShoppingCart(); } dataGridView2.DataSource = _cart.ShoppingItems; dataGridView2.Refresh(); }
static void Main(string[] args) { //demo git change ShoppingService shoppingService = new ShoppingService(); var allProducts = shoppingService.GetAllProducts(); allProducts.ForEach(i => Console.WriteLine(i)); var cart = shoppingService.CreateShoppingCart(); string input = ""; bool canExit = false; do { Console.WriteLine("please input product id or command..."); input = Console.ReadLine().ToLower(); switch (input) { case "exit": case "quit": canExit = true; break; case "checkout": // call check out logic canExit = true; break; default: break; } int productId = 0; if (int.TryParse(input, out productId)) { var buy = shoppingService.BuyProduct(cart.Id, productId); Console.WriteLine(buy.ToString()); } else { Console.WriteLine("please input right product id"); } } while (!canExit); cart.ShoppingItems.ForEach(i => Console.WriteLine($"ProductId={i.ProductId}, Count={i.Count}, TotalPrice={i.TotalPrice}")); Console.WriteLine("thank you, bye"); Console.ReadLine(); }
public IHttpActionResult Post([FromBody] ShoppingCartModel shoppingCartModel) { try { var cart = _service.CreateShoppingCart(shoppingCartModel); return(Ok(cart)); } catch (Exception ex) { return(InternalServerError(ex)); } }
static void Main(string[] args) { ShoppingService shoppingService = new ShoppingService(); var allProducts = shoppingService.GetAllProducts(); allProducts.ForEach(i => Console.WriteLine(i)); var cart = shoppingService.CreateShoppingCart(); string input = ""; bool canExit = false; //string removeCmd = ""; do { Console.WriteLine("please input product id or command..."); input = Console.ReadLine().ToLower(); switch (input) { case "exit": case "quit": canExit = true; break; case "checkout": var receipt = shoppingService.Checkout(cart.Id); Console.WriteLine(receipt); canExit = true; break; case "list": var list = shoppingService.GetShoppingCartItems(cart.Id); list.ForEach(i => Console.WriteLine(i)); break; default: break; } /* * if (input.StartsWith(removeCmd)) * { * string id = input.Substring(removeCmd.Length); * int prodId = ParseProductId(id); * * if (prodId > 0) * { * shoppingService.RemoveProduct(cart.Id, prodId); * } * continue; * } */ int productId = 0; if (int.TryParse(input, out productId)) { var buy = shoppingService.BuyProduct(cart.Id, productId); Console.WriteLine(buy.ToString()); } else { Console.WriteLine("please input right product id"); } } while (!canExit); cart.ShoppingItems.ForEach(i => Console.WriteLine($"ProductId={i.ProductId}, Count={i.Count}, TotalPrice={i.TotalPrice}")); Console.WriteLine("thank you, bye"); Console.ReadLine(); }