Exemplo n.º 1
0
        private string AddProduct(string name, decimal price, string producer)
        {
            var product = new Product(name, price, producer);
            if (!this.productsByProducer.ContainsKey(producer))
            {
                this.productsByProducer.Add(producer, new Bag<Product>());
            }

            this.productsByProducer[producer].Add(product);
            if (!this.productsByName.ContainsKey(name))
            {
                this.productsByName.Add(name, new Bag<Product>());
            }

            this.productsByName[name].Add(product);
            var tuple = new Tuple<string, string>(name, producer);
            if (!this.productsByNameAndProducer.ContainsKey(tuple))
            {
                this.productsByNameAndProducer.Add(tuple, new Bag<Product>());
            }

            this.productsByNameAndProducer[tuple].Add(product);

            this.productsByPrice.Add(price, product);

            return "Product added";
        }
Exemplo n.º 2
0
        public string AddProduct(string name, decimal price, string producer)
        {
                var newProduct = new Product() { Name = name, Price = price, Producer = producer };
            this.productsByName.AppendValueToKey(name, newProduct);
            this.productsByProducer.AppendValueToKey(producer, newProduct);
            this.productsByPrice.AppendValueToKey(price, newProduct);
            this.productsByNameProducer.AppendValueToKey(name + producer, newProduct);

            return "Product added";
        }
Exemplo n.º 3
0
        private string AddProduct(string name, string price, string producer)
        {
            Product product = new Product()
            {
                Name = name,
                Price = decimal.Parse(price),
                Producer = producer
            };

            this.products.Add(product);

            return ProductAdded;
        }
Exemplo n.º 4
0
        private string AddProduct(string name, string price, string producer)
        {
            Product product = new Product()
            {
                Name = name,
                Price = decimal.Parse(price),
                Producer = producer
            };

            this.productsByName.Add(name, product);

            string nameAndProducerKey = this.CombineKeys(name, producer);

            this.productsByNameAndProducer.Add(nameAndProducerKey, product);
            this.productsByPrice.Add(product.Price, product);
            this.productsByProducer.Add(producer, product);

            return ProductAdded;
        }
Exemplo n.º 5
0
        private static string ExecuteAddProduct(string[] lineParams)
        {
            var product = new Product(
                lineParams[0],
                decimal.Parse(lineParams[1]), lineParams[2]);

            byName.Add(product.Name, product);
            byProducer.Add(product.Producer, product);
            byPrice.Add(product.Price, product);
            byProductNameProducer.Add(string.Format("{0};{1}", product.Name, product.Producer), product);

            return ProductAdded;
        }