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"; }
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"; }
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; }
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; }
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; }