/// <summary> /// Enregistre ou met a jour un evenement /// </summary> public void Save() { if (this.Id == Guid.Empty) { this.Metier.Id = Guid.NewGuid(); this.Metier.ImageEvenement.Id = Guid.NewGuid(); this.Metier.AdresseEvenement.Id = Guid.NewGuid(); using (ParkingContext context = new ParkingContext()) { ServiceAdresse.Insert(this.Metier.AdresseEvenement, context); ServiceImage.Insert(this.Metier.ImageEvenement, context); string query = "https://maps.googleapis.com/maps/api/geocode/json?address=" + this.Metier.AdresseEvenement.ToString() + "&key=AIzaSyCyoqbqJVd_MtZRT_0DmYmznxxJWRfMjQI"; using (WebClient wc = new WebClient()) { var json = wc.DownloadString(query); RootObjectGoogle item = JsonConvert.DeserializeObject <RootObjectGoogle>(json); if (item != null) { this.Metier.AdresseEvenement.lat = item.results.FirstOrDefault().geometry.location.lat; this.Metier.AdresseEvenement.lng = item.results.FirstOrDefault().geometry.location.lng; } } ServiceEvenement.Insert(this.Metier, context); context.SaveChanges(); } } else { ServiceEvenement.Update(this.Metier); } }
public static void AddtoBase() { List <Parking> parkingToAdd = new List <Parking>(); //recupere les parkings using (ParkingContext context = new ParkingContext()) { using (WebClient wc = new WebClient()) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://data.citedia.com/r1/parks/timetable-and-prices"); StreamReader reader; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { reader = new StreamReader(response.GetResponseStream()); List <string[]> csvfile = new List <string[]>();// = reader.ReadToEnd(); string line; while ((line = reader.ReadLine()) != null) { csvfile.Add(Regex.Matches(line, @"[\""].+?[\""]|[^;]+").Cast <Match>().Select(m => m.Value).ToArray()); } reader.Close(); int count = 0; foreach (string[] stringtab in csvfile) { if (count != 0) { var json = wc.DownloadString("http://data.citedia.com/r1/parks/" + stringtab[0]); dynamic data = JsonConvert.DeserializeObject <ParkInformation>(json); Adresse adresse = new Adresse(Guid.NewGuid(), stringtab[3], 0, 35000, "rennes", "france", true); Parking parking = new Parking(Guid.NewGuid(), RemoveDiacritics(stringtab[0]), adresse, data.max, data.free, RemoveDiacritics(stringtab[2]), RemoveDiacritics(stringtab[1]), data.status); ServiceAdresse.Insert(adresse, context); ServiceParking.Insert(parking, context); //Suppression des anciennes données ServiceParking.DeleteAll(); ServiceAdresse.DeleteParking(); parkingToAdd.Add(parking); } count++; } } context.Parkings.AddRange(parkingToAdd); context.SaveChanges(); } } }
/// <summary> /// Enregistre ou met a jour un Adresse /// </summary> public void Save() { if (this.Id == Guid.Empty) { this.Metier.Id = Guid.NewGuid(); ServiceAdresse.Insert(this.Metier); } else { ServiceAdresse.Update(this.Metier); } }