public override void Delete(Geoname geoname) { if (geoname.EntityState == EntityState.Deleted) { this._entities.Geonames.Attach(geoname); } this._entities.Geonames.DeleteObject(geoname); }
/// <summary> /// Create a new Geoname object. /// </summary> /// <param name="locationID">Initial value of the LocationID property.</param> /// <param name="country">Initial value of the Country property.</param> /// <param name="county">Initial value of the County property.</param> /// <param name="name">Initial value of the Name property.</param> public static Geoname CreateGeoname(global::System.Int32 locationID, global::System.String country, global::System.String county, global::System.String name) { Geoname geoname = new Geoname(); geoname.LocationID = locationID; geoname.Country = country; geoname.County = county; geoname.Name = name; return(geoname); }
public List <Weather> FindWeathers(Geoname geoname, string screenName) { var requestUrlstring = String.Format("http://www.yr.no/place/{0}/{1}/{2}/forecast.xml", geoname.Country, geoname.County, geoname.Name); var document = LoadDocument(requestUrlstring); return((from time in document.Descendants("time") // Väljer ut alla time noder. where Int32.Parse(time.Attribute("period").Value) >= 2 // Där periodens värde är större eller lika med 2. group time by DateTime.Parse(time.Attribute("from").Value).Date into g // Gruppera perioderna per dag. Välj sedan ut den första i varje par. select(from t in g select t).First()).Take(5).Select(forecast => YrFactory.Create(forecast, geoname.LocationID)).ToList()); }
public List<Weather> FindWeathers(Geoname geoname, string screenName) { var requestUrlstring = String.Format("http://www.yr.no/place/{0}/{1}/{2}/forecast.xml", geoname.Country, geoname.County, geoname.Name); var document = LoadDocument(requestUrlstring); return (from time in document.Descendants("time") // Väljer ut alla time noder. where Int32.Parse(time.Attribute("period").Value) >= 2 // Där periodens värde är större eller lika med 2. group time by DateTime.Parse(time.Attribute("from").Value).Date into g // Gruppera perioderna per dag. Välj sedan ut den första i varje par. select (from t in g select t).First()).Take(5).Select(forecast => YrFactory.Create(forecast, geoname.LocationID)).ToList(); }
public override void Update(Geoname geoname) { ObjectStateEntry entry; if (!this._entities.ObjectStateManager.TryGetObjectStateEntry(geoname, out entry) || entry.State == EntityState.Detached) { this._entities.Geonames.Attach(geoname); } if (geoname.EntityState != EntityState.Modified) { this._entities.ObjectStateManager.ChangeObjectState(geoname, EntityState.Modified); } }
public List<Weather> FindWeathers(Geoname geoname, string screenName, int locationID) { // Gets weather forecasts var weathers = this._repository.QueryWeather().Where(t => t.LocationID == locationID).OrderBy(w => w.Time).ToList(); // Checks if there are any weather forecasts saved in db and if datetime hasn't occured if (!weathers.Any()) { // ...aktivates web service if no post with city exists var webservice = new GeonameWebservice(); weathers = webservice.FindWeathers(geoname, screenName); // for every object sets FK from parameter int. weathers.ForEach(t => t.LocationID = locationID); // ...update the location and save the weather in the database. geoname.NextUpdate = DateTime.Now.AddMinutes(10); weathers.ForEach(t => this._repository.Add(t)); //weathers.ForEach(t => this._repository.Update(t)); this._repository.Save(); } else { // ...delete the old(?) weathers (if there are any),... weathers.ForEach(t => this._repository.Delete(t)); var webservice = new GeonameWebservice(); weathers = webservice.FindWeathers(geoname, screenName); weathers.ForEach(t => t.LocationID = locationID); // ...update the user and save the weathers in the database. geoname.NextUpdate = DateTime.Now.AddMinutes(10); weathers.ForEach(t => this._repository.Add(t)); this._repository.Save(); } return weathers; }
public List <Weather> FindWeathers(Geoname geoname, string screenName, int locationID) { // Gets weather forecasts var weathers = this._repository.QueryWeather().Where(t => t.LocationID == locationID).OrderBy(w => w.Time).ToList(); // Checks if there are any weather forecasts saved in db and if datetime hasn't occured if (!weathers.Any()) { // ...aktivates web service if no post with city exists var webservice = new GeonameWebservice(); weathers = webservice.FindWeathers(geoname, screenName); // for every object sets FK from parameter int. weathers.ForEach(t => t.LocationID = locationID); // ...update the location and save the weather in the database. geoname.NextUpdate = DateTime.Now.AddMinutes(10); weathers.ForEach(t => this._repository.Add(t)); //weathers.ForEach(t => this._repository.Update(t)); this._repository.Save(); } else { // ...delete the old(?) weathers (if there are any),... weathers.ForEach(t => this._repository.Delete(t)); var webservice = new GeonameWebservice(); weathers = webservice.FindWeathers(geoname, screenName); weathers.ForEach(t => t.LocationID = locationID); // ...update the user and save the weathers in the database. geoname.NextUpdate = DateTime.Now.AddMinutes(10); weathers.ForEach(t => this._repository.Add(t)); this._repository.Save(); } return(weathers); }
/// <summary> /// Create a new Geoname object. /// </summary> /// <param name="locationID">Initial value of the LocationID property.</param> /// <param name="country">Initial value of the Country property.</param> /// <param name="county">Initial value of the County property.</param> /// <param name="name">Initial value of the Name property.</param> public static Geoname CreateGeoname(global::System.Int32 locationID, global::System.String country, global::System.String county, global::System.String name) { Geoname geoname = new Geoname(); geoname.LocationID = locationID; geoname.Country = country; geoname.County = county; geoname.Name = name; return geoname; }
/// <summary> /// Deprecated Method for adding a new object to the Geonames EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToGeonames(Geoname geoname) { base.AddObject("Geonames", geoname); }
public override void Add(Geoname geoname) { this._entities.Geonames.AddObject(geoname); }