public void Add(ItemCatalogData item) { if (_items.Contains(item)) { return; } _items.Add(item); }
private static void UpdateItemDetails(ItemCatalogData itemCatalogData, Dictionary <int, List <ItemFullData> > fullData) { foreach (var item in fullData) { if (itemCatalogData.ItemId != item.Key) { continue; } UpdatePrices(itemCatalogData, item); } }
private static void UpdatePrices(ItemCatalogData itemCatalogData, KeyValuePair <int, List <ItemFullData> > item) { foreach (var itemFullData in item.Value) { //Update catalog from full data double price; double.TryParse(itemFullData.ItemPrice, out price); if (!itemCatalogData.PricesByChainName.ContainsKey(itemFullData.ChainName)) { itemCatalogData.PricesByChainName.Add(itemFullData.ChainName, 0); } itemCatalogData.PricesByChainName[itemFullData.ChainName] = price; } }
public void Remove(ItemCatalogData item) { var categoryKey = item.Category; if (!_catalog.ContainsKey(categoryKey)) { return; } _catalog[categoryKey].Remove(item); if (_catalog[categoryKey].Count == 0) { _catalog.Remove(categoryKey); } }
public void Add(ItemCatalogData item) { var categoryKey = item.Category; /*You have made four dictionary lookup's where two would fit you just fine. * Consider refactoring this method. */ if (!_catalog.ContainsKey(categoryKey)) { _catalog.Add(categoryKey, new List <ItemCatalogData>()); } if (!_catalog[categoryKey].Contains(item)) { _catalog[categoryKey].Add(item); } }