Example #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);
                }
            }
        }
        public double CurrentMassKg()
        {
            var cargoList     = CargoItems.ToList <Payload>();
            var astronautList = Astronauts.ToList <Payload>();

            return(SumMass(cargoList) + SumMass(astronautList));
        }
 public bool AddCargo(Cargo cargo)
 {
     if (CanAdd(cargo))
     {
         CargoItems.Add(cargo);
         return(true);
     }
     return(false);
 }