예제 #1
0
 public void AddProductIfNoExistis(Product product)
 {
     if (!Products.Any(chromosom => chromosom.Name == product.Name))
     {
         Products.Add(product);
         saveProductToJSON();
     }
 }
        private void ReadRandomNouns()
        {
            //int counter = 0;
            string line;
            Random random = new Random();
            // Read the file and display it line by line.
            StreamReader file = new StreamReader(Path.Combine(Environment.CurrentDirectory, DirectoryName, "random150nouns.txt"));
            while ((line = file.ReadLine()) != null)
            {
                Product product = new Product
                {
                    Name = Regex.Replace(line, @"\s+", ""),
                    SurvivalPoints = random.Next(0, 30),
                    Weight = random.Next(0, 30)
                };
                
                Things things = new Things();
                things.AddProductIfNoExistis(product);
                Console.WriteLine(line);
                //counter++;
            }

            file.Close();
        }
예제 #3
0
 public void RemoveProduct(Product product)
 {
     Products.Remove(product);
     saveProductToJSON();
 }