public void LoadPartyFromStaticData(int partyId) { Party = HardCodedSampleData.SampleParties.Single(p => p.Id == partyId); }
/// <summary> /// Populates view model from saved page state that was previously populated with LoadState /// </summary> /// <returns>Whether or not any saved state was found and loaded</returns> public bool LoadState(int partyId, IDictionary<string, object> savedState) { if (savedState == null || savedState.Count == 0) { return false; } var uniqueId = PartyIdToUniqueId(partyId); var savedParty = savedState[uniqueId] as Party; if (savedParty == null) { return false; } Party = savedParty; // Now check for known character IDs var uniquePartyCharactersId = PartyIdToUniquePartyCharactersId(partyId); var savedCharacterIds = savedState[uniquePartyCharactersId] as IEnumerable<int>; if (savedCharacterIds == null) return true; // We loaded something... foreach (var savedCharacterId in savedCharacterIds) { var characterViewModel = new CharacterViewModel(); if (characterViewModel.LoadState(savedCharacterId, savedState)) { Characters.Add(characterViewModel); } } return true; }
/// <summary> /// Populates the PartyViewModel from the given Party data and populates its children with data /// from the given list of knownCharacters. /// </summary> /// <param name="party"></param> /// <param name="knownCharacters">The set of characters to draw CharacterViewModel data from. /// It's okay for knownCharacters to contain more characters than the party (they'll be ignored), /// and it's also okay for it to be missing characters (they won't be displayed).</param> public PartyViewModel(Party party, IEnumerable<Character> knownCharacters) : this() { this.Party = party; SetModels(knownCharacters.Where(c => c.PartyId == party.Id)); }