SpsModel.cs CampusAppWP8::Model::GeoDb::SpsModel CampusAppWP8::Model::GeoDb //----------------------------------------------------------------------- //<copyrightfile="SpsModel.cs"company="BTU/IIT"> //TheMITLicense(MIT).Copyright(c)2013BTU/IIT. //</copyright> //<author>Stubbfel</author> //<date>15.10.2013</date> //<summary>Implementsthespsmodelclass</summary> //----------------------------------------------------------------------- namespaceCampusAppWP8.Model.GeoDb { usingSystem.Collections.Generic; usingSystem.Collections.ObjectModel; usingSystem.Linq; usingSystem.Xml.Serialization; [XmlRoot("root")] publicclassSpsModel { #regionConstructor publicSpsModel() { this.HasChanged=false; this.Places=newObservableCollection<PlaceModel>(); } #endregion #regionProperty [XmlElement("place")] publicObservableCollection<PlaceModel>Places{get;set;} publicboolHasChanged{get;set;} #endregion #regionMethod #regionpublic publicList<PlaceModel>GetPlacesByInformation(stringquery,boolignoreCases=true,List<string>informationNames=null) { stringquerryStr=string.Empty; List<PlaceModel>resultplaces=newList<PlaceModel>(); foreach(PlaceModelplaceinthis.Places) { if(this.IsPlaceQueryMatched(place,query,ignoreCases,informationNames)) { resultplaces.Add(place); } } returnresultplaces; } publicvoidAddPlaces(List<PlaceModel>places) { foreach(PlaceModelplaceinplaces) { if(this.Places.Contains(place)) { intindex=this.Places.IndexOf(place); this.Places[index].AddPlaceInformations(place.Informations.ToList()); this.Places[index].AddPlaceServices(place.Services.ToList()); } else { this.Places.Add(place); } } this.HasChanged=true; } publicList<string>CreatePidList() { List<string>pidList=newList<string>(); foreach(PlaceModelplaceinthis.Places) { pidList.Add(place.PlaceId); } returnpidList; } publicPlaceModelGetPlaceById(stringid) { foreach(PlaceModelplaceinthis.Places) { if(place.PlaceId.Equals(id)) { returnplace; } } returnnull; } publicboolContainsInformationNames(List<string>pidList,List<string>names) { foreach(stringpidinpidList) { PlaceModelplace=this.GetPlaceById(pid); if(!place.ContainsInformationNames(names)) { returnfalse; } } returntrue; } publicboolContainsServiceNames(List<string>pidList,List<string>names) { foreach(stringpidinpidList) { PlaceModelplace=this.GetPlaceById(pid); if(!place.ContainsServiceNames(names)) { returnfalse; } } returntrue; } publicList<PlaceModel>FilterByPid(List<string>pidList) { List<PlaceModel>fitlerList=newList<PlaceModel>(); if(pidList==null||pidList.Count<1) { returnfitlerList; } foreach(PlaceModelplaceinthis.Places) { if(pidList.Contains(place.PlaceId)) { fitlerList.Add(place); } } returnfitlerList; } #endregion #regionprivate privateboolIsPlaceQueryMatched(PlaceModelplace,stringquery,boolignoreCases=true,List<string>informationNames=null) { stringqueryString=query; if(ignoreCases) { queryString=query.ToLower(); } boolallInfos=true; if(informationNames!=null&&informationNames.Count>0) { allInfos=false; } foreach(PlaceInformationinfoinplace.Informations) { if(allInfos||informationNames.Contains(info.InformationName)) { stringinfoVal=info.InformationValue; if(ignoreCases) { infoVal=infoVal.ToLower(); } if(infoVal.Contains(queryString)) { returntrue; } } } returnfalse; } #endregion #endregion } }