RouteDatabase.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using System.Collections.Generic;
  4. using System.Collections.ObjectModel;
  5. using System.IO;
  6. using System.Linq;
  7. namespace Breda_Tour.Data
  8. {
  9. class RouteDatabase
  10. {
  11. public List<Route> Routes;
  12. public RouteDatabase()
  13. {
  14. Routes = new List<Route>();
  15. readRoutes();
  16. }
  17. private void readRoutes()
  18. {
  19. string json = File.ReadAllText("Storage/Routes/routes.json");
  20. JObject JsonObject = JObject.Parse(json);
  21. IList<JToken> JsonList = JsonObject["Routes"].ToList();
  22. foreach (JToken route in JsonList)
  23. {
  24. Routes.Add(JsonConvert.DeserializeObject<Route>(route.ToString()));
  25. }
  26. }
  27. public ObservableCollection<Route> GetCurrentRoutes()
  28. {
  29. ObservableCollection<Route> routes = new ObservableCollection<Route>();
  30. foreach (var route in Routes)
  31. {
  32. if (route.Language == App.Language)
  33. routes.Add(route);
  34. }
  35. return routes;
  36. }
  37. }
  38. }