public ItemViewModel(Item item) : base(item, DomainObjectRepositories.ItemRepository) { _transient = true; _metaData = ItemMetaDataProvider.GetMetaData(item); //_metaData.Refreshed += (sender, args) => UpdateMetaDataProperties(); item.ObjectSaved += (sender, args) => { UpdateMetaDataProperties(); }; UpdateMetaDataProperties(); MadeFrom = new RecipeCollectionViewModel(item.MadeFrom, item); foreach (var i in MadeFrom.Collection) { i.PropertyChanged += (sender, args) => { if (args.PropertyName == nameof(UnitCost)) { _metaData.Recalculate(); UpdateMetaDataProperties(); } }; } UsedIn = new RecipeCollectionViewModel(item.UsedIn); var primaryRecipe = item.MadeFrom.FirstOrDefault(); if (primaryRecipe != null) { PrimarySourceRecipe = new RecipeViewModel(primaryRecipe); } MarketObservationCollection = new MarketObservationCollectionViewModel(item.AllMarketData, item); MarketObservationCollection.Collection.CollectionChanged += MarketObservationCollection_CollectionChanged; if (item.CurrentMarketData != null) { MostRecentMarketObservation = new MarketObservationViewModel(item.CurrentMarketData); } else { MessageLog.GetLog().LogMessage($"Couldn't find any market data for {item.Name}"); } MarketCategories = CollectionHelper.MarketCategories; _transient = item.Id == Guid.Empty; }
void MarketObservationCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs) { if (notifyCollectionChangedEventArgs.Action == NotifyCollectionChangedAction.Add) { if (DomainObject.CurrentMarketData != null) { MostRecentMarketObservation = new MarketObservationViewModel(DomainObject.CurrentMarketData); //this doesn't actually save the object, despite the incredibly straightforward name of the method DomainObject.Save(); } } //Recalculate(); //RefreshHelper.NotifyChanged(DomainObject); }
public void RefreshMarket() { _transient = true; MessageLog.GetLog().LogMessage($"Refreshing market data for {DomainObject.Name}"); MarketObservationCollection.Collection.CollectionChanged -= MarketObservationCollection_CollectionChanged; MarketObservationCollection = new MarketObservationCollectionViewModel(DomainObject.AllMarketData, DomainObject); MarketObservationCollection.Collection.CollectionChanged += MarketObservationCollection_CollectionChanged; if (DomainObject.CurrentMarketData != null) { MostRecentMarketObservation = new MarketObservationViewModel(DomainObject.CurrentMarketData); } else { MessageLog.GetLog().LogMessage($"Couldn't find any market data for {DomainObject.Name}"); } UpdateMetaDataProperties(); _transient = false; }