コード例 #1
0
ファイル: PartyViewModel.cs プロジェクト: ianw89/DragonAid
 public void LoadPartyFromStaticData(int partyId)
 {
     Party = HardCodedSampleData.SampleParties.Single(p => p.Id == partyId);
 }
コード例 #2
0
ファイル: PartyViewModel.cs プロジェクト: ianw89/DragonAid
        /// <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;
        }
コード例 #3
0
ファイル: PartyViewModel.cs プロジェクト: ianw89/DragonAid
 /// <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));
 }