Ejemplo n.º 1
0
        public void Update()
        {
            if (_maxCapacity != _typeStore.MaxCapacityKg)
            {
                _maxCapacity = _typeStore.MaxCapacityKg;
                MaxCapacity  = _maxCapacity.ToString();
            }
            if (_freeCapacity != _typeStore.FreeCapacityKg)
            {
                _freeCapacity = _typeStore.FreeCapacityKg;
                FreeCapacity  = _freeCapacity.ToString();
            }

            HeaderText = StorageTypeName + " " + FreeCapacity + "/" + MaxCapacity + " Free";

            foreach (var kvp in _typeStore.ItemsAndAmounts.ToArray())
            {
                if (!_cargoItemsDict.ContainsKey(kvp.Key))
                {                                                                             //if the key from the DB's dictionary is not in our dictionary here
                    var newCargoItemVM = new CargoItemVM(_staticData.GetICargoable(kvp.Key)); //then create a new CargoItemVM
                    _cargoItemsDict.Add(kvp.Key, newCargoItemVM);                             //add it to the dictionary
                    CargoItems.Add(newCargoItemVM);                                           //then add it to the observable collection
                }
                _cargoItemsDict[kvp.Key].Update(kvp.Value);                                   //since the object in the observable collection is the same object as the one in the dictionary, update the object via the dictionary
            }

            foreach (var key in _cargoItemsDict.Keys.ToArray())
            {
                if (!_typeStore.ItemsAndAmounts.ContainsKey(key))
                {
                    CargoItems.Remove(_cargoItemsDict[key]);
                    _cargoItemsDict.Remove(key);
                }
            }
        }
Ejemplo n.º 2
0
 public CargoItemVM GetOrAddItemVM(ICargoable cargoableItem)
 {
     if (!_cargoItemsDict.ContainsKey(cargoableItem.ID))
     {
         var itemVM = new CargoItemVM(cargoableItem);
         _cargoItemsDict.Add(cargoableItem.ID, itemVM);
         CargoItems.Add(itemVM);
     }
     return(_cargoItemsDict[cargoableItem.ID]);
 }