SpsModel.cs CampusAppWP8::Model::GeoDb::SpsModel CampusAppWP8::Model::GeoDb //----------------------------------------------------------------------- //<copyrightfile="SpsModel.cs"company="BTU/IIT"> //Companycopyrighttag. //</copyright> //<author>stubbfel</author> //<sience>08.08.2013</sience> //---------------------------------------------------------------------- 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 publicList<PlaceModel>GetPlacesByInformation(stringquery,boolignoreCases=true,stringinformationName=null) { stringquerryLow=string.Empty; IEnumerable<PlaceModel>resultplaces=null; //selectcorrectstatement if(ignoreCases&&informationName==null) { querryLow=query.ToLower(); resultplaces=fromplaceinthis.Places frominfoinplace.Informations whereinfo.InformationValue.ToLower().Contains(querryLow) selectplace; } elseif(ignoreCases&&informationName!=null) { querryLow=query.ToLower(); resultplaces=fromplaceinthis.Places frominfoinplace.Informations whereinfo.InformationValue.ToLower().Contains(querryLow)&&info.InformationName.Equals(informationName) selectplace; } elseif(!ignoreCases&&informationName==null) { resultplaces=fromplaceinthis.Places frominfoinplace.Informations whereinfo.InformationValue.Contains(querryLow) selectplace; } elseif(!ignoreCases&&informationName!=null) { resultplaces=fromplaceinthis.Places frominfoinplace.Informations whereinfo.InformationValue.Contains(querryLow)&&info.InformationName.Equals(informationName) selectplace; } //nullassert if(resultplaces==null) { returnnull; } returnresultplaces.ToList<PlaceModel>(); } 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>(); foreach(PlaceModelplaceinthis.Places) { if(pidList.Contains(place.PlaceId)) { fitlerList.Add(place); } } returnfitlerList; } #endregion } }