private static void InitDataCategories() { // ProductCategory Model.ProductCategory model1 = new Model.ProductCategory(); model1.ID = Guid.NewGuid(); model1.Name = "Shirt"; listProductCategory.Add(model1); // Product Model.Product model2 = new Model.Product(); model2.ID = "1"; model2.ProductCategoryID = listProductCategory.Find(x => x.Name == "Shirt").ID; model2.Name = "T-Shirt"; model2.IsUsed = true; listProduct.Add(model2); model2 = new Model.Product(); model2.ID = "2"; model2.ProductCategoryID = listProductCategory.Find(x => x.Name == "Shirt").ID; model2.Name = "Dress Shirt"; model2.IsUsed = true; listProduct.Add(model2); // ProductPrice Model.ProductSellPrice model3 = new Model.ProductSellPrice(); model3.ID = Guid.NewGuid(); model3.ProductID = listProduct.Find(x => x.Name == "T-Shirt").ID; model3.Price = 12; listProductSellPrice.Add(model3); model3 = new Model.ProductSellPrice(); model3.ID = Guid.NewGuid(); model3.ProductID = listProduct.Find(x => x.Name == "Dress Shirt").ID; model3.Price = 20; listProductSellPrice.Add(model3); l_color.Add("Red"); l_color.Add("Blue"); l_size.Add("S"); l_size.Add("M"); }
private static void SellProductDetail(ref Model.TransactionDetail detail1) { try { string l_pname = ""; string l_pcolor = ""; string l_psize = ""; List <string> l_pId = new List <string>(); foreach (var item in listProduct) { l_pname += (string.IsNullOrEmpty(l_pname) ? "" : ";") + item.ID + " for " + item.Name; l_pId.Add(item.ID); } foreach (var item in l_size) { l_psize += (string.IsNullOrEmpty(l_psize) ? "" : ";") + item; } foreach (var item in l_color) { l_pcolor += (string.IsNullOrEmpty(l_pcolor) ? "" : ";") + item; } Console.WriteLine("Select Product (" + l_pname + "): "); string productID = Console.ReadLine(); string size = ""; string color = ""; int quantity_d = 0; decimal amount_d = 0; decimal price = 0; bool exists = (l_pId.Find(p => p.ToString() == productID).Count() > 0 ? true : false); Model.ProductSellPrice selectedProduct = listProductSellPrice.Where(p => p.ProductID == productID && p.DateApply < DateTime.Now).OrderByDescending(x => x.DateApply).FirstOrDefault(); if (exists) { Console.WriteLine("Select Size (" + l_psize + ") "); size = Console.ReadLine(); bool exists_s = (l_size.Find(p => p.ToString() == size).Count() > 0 ? true : false); if (exists_s) { Console.WriteLine("Select Color (" + l_pcolor + ") "); color = Console.ReadLine(); bool exists_c = (l_color.Find(p => p.ToString() == color).Count() > 0 ? true : false); if (exists_c) { Console.WriteLine("Input Quantity:"); try { quantity_d = Convert.ToInt16(Console.ReadLine()); Console.WriteLine("Price:" + selectedProduct.Price.ToString()); price = selectedProduct.Price; amount_d = quantity_d * price; detail1.ID = Guid.NewGuid(); detail1.ProductID = productID; detail1.Quantity = quantity_d; detail1.Size = size; detail1.Color = color; detail1.Amount = amount_d; detail1.Price = price; } catch { Console.WriteLine(" Please input quantity"); } } else { Console.WriteLine(" Please select size item in list " + l_psize); } } else { Console.WriteLine(" Please select color item in list " + l_psize); } } else { Console.WriteLine(" Please selct item in list " + l_pname); } } catch (Exception) { Console.WriteLine("Has error when buy item"); throw; } }