using System; using System.Collections.Generic; using System.IO; using Globals.classes; using Globals.Interfaces; using Newtonsoft.Json; namespace Data { public class dataLayer : IData { public dataLayer() { } public List getBets() { List list = new List(); try { using (StreamReader file = File.OpenText(@"../../Data/bets.json")) { JsonSerializer serializer = new JsonSerializer(); list = (List)serializer.Deserialize(file, typeof(List)); } } catch (Exception e) { throw new Exception(e.Message); } return list; } public List getGames() { List list = new List(); try { using (StreamReader file = File.OpenText(@"../../Data/games.json")) { JsonSerializer serializer = new JsonSerializer(); list = (List)serializer.Deserialize(file, typeof(List)); } } catch (Exception e) { throw new Exception(e.Message); } return list; } public List getPersons() { List list = new List(); try { using (StreamReader file = File.OpenText(@"../../Data/persons.json")) { JsonSerializer serializer = new JsonSerializer(); list = (List)serializer.Deserialize(file, typeof(List)); } } catch (Exception e) { throw new Exception(e.Message); } return list; } public List getPloegen() { List list = new List(); try { using (StreamReader file = File.OpenText(@"../../Data/ploegen.json")) { JsonSerializer serializer = new JsonSerializer(); list = (List)serializer.Deserialize(file, typeof(List)); } } catch (Exception e) { throw new Exception(e.Message); } return list; } public void saveBets(List b) { using (StreamWriter file = File.CreateText(@"../../Data/bets.json")) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, b); } } public void saveGames(List g) { using (StreamWriter file = File.CreateText(@"../../Data/games.json")) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, g); } } public void savePersons(List p) { using (StreamWriter file = File.CreateText(@"../../Data/persons.json")) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, p); } } public void savePloegen(List p) { using (StreamWriter file = File.CreateText(@"../../Data/ploegen.json")) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, p); } } } }