ui nog wa aanpasse en we zijn gucci

This commit is contained in:
Beppe Vanrolleghem
2019-08-12 18:15:17 +02:00
parent fb078ec1d8
commit 582c3f7244
27 changed files with 225 additions and 352 deletions

View File

@@ -34,6 +34,7 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="db.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="data.cs" /> <Compile Include="data.cs" />
</ItemGroup> </ItemGroup>

View File

@@ -7,127 +7,38 @@ using Newtonsoft.Json;
namespace Data namespace Data
{ {
public class dataLayer : IData public class dataLayer
{ {
public dataLayer() public dataLayer()
{ {
} }
public db getDb()
public List<Bet> getBets()
{ {
List<Bet> list = new List<Bet>();
try try
{ {
using (StreamReader file = File.OpenText(@"../../Data/bets.json")) using (StreamReader file = File.OpenText(@"../../Data/db.json"))
{
JsonSerializer serializer = new JsonSerializer();
list = (List<Bet>)serializer.Deserialize(file, typeof(List<Bet>));
}
} catch (Exception e)
{
throw new Exception(e.Message);
}
return list;
}
public List<Game> getGames()
{
List<Game> list = new List<Game>();
try
{
using (StreamReader file = File.OpenText(@"../../Data/games.json"))
{ {
JsonSerializer serializer = new JsonSerializer(); JsonSerializer serializer = new JsonSerializer();
list = (List<Game>)serializer.Deserialize(file, typeof(List<Game>)); return (db)serializer.Deserialize(file, typeof(db));
} }
} catch (Exception e) } catch (Exception ex)
{ {
throw new Exception(ex.Message);
throw new Exception(e.Message);
} }
return list;
} }
public List<Person> getPersons()
public void saveDb(db d)
{ {
using (StreamWriter file = File.CreateText(@"../../Data/db.json"))
List<Person> list = new List<Person>();
try {
using (StreamReader file = File.OpenText(@"../../Data/persons.json"))
{
JsonSerializer serializer = new JsonSerializer();
list = (List<Person>)serializer.Deserialize(file, typeof(List<Person>));
}
} catch (Exception e)
{
throw new Exception(e.Message);
}
return list;
}
public List<Ploeg> getPloegen()
{
List<Ploeg> list = new List<Ploeg>();
try
{
using (StreamReader file = File.OpenText(@"../../Data/ploegen.json"))
{
JsonSerializer serializer = new JsonSerializer();
list = (List<Ploeg>)serializer.Deserialize(file, typeof(List<Ploeg>));
}
} catch (Exception e)
{
throw new Exception(e.Message);
}
return list;
}
public void saveBets(List<Bet> b)
{
using (StreamWriter file = File.CreateText(@"../../Data/bets.json"))
{ {
JsonSerializer serializer = new JsonSerializer(); JsonSerializer serializer = new JsonSerializer();
serializer.Serialize(file, b); serializer.Serialize(file, d);
} }
} }
public void saveGames(List<Game> g)
{
using (StreamWriter file = File.CreateText(@"../../Data/games.json"))
{
JsonSerializer serializer = new JsonSerializer();
serializer.Serialize(file, g);
}
}
public void savePersons(List<Person> p)
{
using (StreamWriter file = File.CreateText(@"../../Data/persons.json"))
{
JsonSerializer serializer = new JsonSerializer();
serializer.Serialize(file, p);
}
}
public void savePloegen(List<Ploeg> p)
{
using (StreamWriter file = File.CreateText(@"../../Data/ploegen.json"))
{
JsonSerializer serializer = new JsonSerializer();
serializer.Serialize(file, p);
}
}
} }
} }

View File

@@ -0,0 +1,18 @@
using Globals.classes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Data
{
public class db
{
public List<Person> persons { get; set; }
public List<Bet> bets { get; set; }
public List<Ploeg> ploegen { get; set; }
public List<Game> games { get; set; }
public List<PloegInMatch> ploegInMatches { get; set; }
}
}

View File

@@ -83,6 +83,7 @@
this.listBox1.Name = "listBox1"; this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(120, 95); this.listBox1.Size = new System.Drawing.Size(120, 95);
this.listBox1.TabIndex = 4; this.listBox1.TabIndex = 4;
this.listBox1.SelectedIndexChanged += new System.EventHandler(this.ListBox1_SelectedIndexChanged);
// //
// label1 // label1
// //
@@ -106,6 +107,7 @@
this.Controls.Add(this.button1); this.Controls.Add(this.button1);
this.Name = "Admin"; this.Name = "Admin";
this.Text = "Admin"; this.Text = "Admin";
this.Load += new System.EventHandler(this.Admin_Load);
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();

View File

@@ -16,7 +16,7 @@ namespace GUI_Gokkantoor
public LogicLayer l; public LogicLayer l;
public Admin(LogicLayer l) public Admin(LogicLayer l)
{ {
l = new LogicLayer(); this.l = l;
InitializeComponent(); InitializeComponent();
} }
@@ -55,5 +55,15 @@ namespace GUI_Gokkantoor
a.FormClosed += adminClosed; a.FormClosed += adminClosed;
a.Show(); a.Show();
} }
private void Admin_Load(object sender, EventArgs e)
{
listBox1.DataSource = l.GetGames();
}
private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
} }
} }

View File

@@ -0,0 +1 @@
{"persons":[{"Id":0,"name":"John","lastname":"Smith","adress":"123","gsm":"456","balance":789.0}],"bets":[],"ploegen":[],"games":[],"ploegInMatches":[]}

View File

@@ -147,10 +147,7 @@
<EmbeddedResource Include="User.resx"> <EmbeddedResource Include="User.resx">
<DependentUpon>User.cs</DependentUpon> <DependentUpon>User.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<None Include="Data\bets.json" /> <None Include="Data\db.json" />
<None Include="Data\games.json" />
<None Include="Data\persons.json" />
<None Include="Data\ploegen.json" />
<None Include="Properties\Settings.settings"> <None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput> <LastGenOutput>Settings.Designer.cs</LastGenOutput>

View File

@@ -47,6 +47,7 @@
this.ListMatch.Name = "ListMatch"; this.ListMatch.Name = "ListMatch";
this.ListMatch.Size = new System.Drawing.Size(120, 95); this.ListMatch.Size = new System.Drawing.Size(120, 95);
this.ListMatch.TabIndex = 0; this.ListMatch.TabIndex = 0;
this.ListMatch.SelectedIndexChanged += new System.EventHandler(this.ListMatch_SelectedIndexChanged);
// //
// ListGokken // ListGokken
// //
@@ -150,6 +151,7 @@
this.Controls.Add(this.ListMatch); this.Controls.Add(this.ListMatch);
this.Name = "Gokspel"; this.Name = "Gokspel";
this.Text = "Gokspel"; this.Text = "Gokspel";
this.Load += new System.EventHandler(this.Gokspel_Load);
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();

View File

@@ -57,5 +57,15 @@ namespace GUI_Gokkantoor
{ {
} }
private void Gokspel_Load(object sender, EventArgs e)
{
}
private void ListMatch_SelectedIndexChanged(object sender, EventArgs e)
{
}
} }
} }

View File

@@ -19,8 +19,7 @@ namespace GUI_Gokkantoor
{ {
this.l = l; this.l = l;
InitializeComponent(); InitializeComponent();
listBox1.DataSource = l.persons; listBox1.DataSource = l.GetPeople();
listBox1.DataSource = l.persons;
} }

View File

@@ -57,6 +57,7 @@
this.button1.TabIndex = 2; this.button1.TabIndex = 2;
this.button1.Text = "Toevoegen"; this.button1.Text = "Toevoegen";
this.button1.UseVisualStyleBackColor = true; this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.Button1_Click);
// //
// Team // Team
// //

View File

@@ -16,5 +16,10 @@ namespace GUI_Gokkantoor
{ {
InitializeComponent(); InitializeComponent();
} }
private void Button1_Click(object sender, EventArgs e)
{
}
} }
} }

View File

@@ -28,11 +28,11 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.textBox1 = new System.Windows.Forms.TextBox(); this.naam = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox(); this.achternaam = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox(); this.adres = new System.Windows.Forms.TextBox();
this.textBox4 = new System.Windows.Forms.TextBox(); this.gsm = new System.Windows.Forms.TextBox();
this.textBox5 = new System.Windows.Forms.TextBox(); this.balans = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label();
@@ -41,40 +41,40 @@
this.button1 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout(); this.SuspendLayout();
// //
// textBox1 // naam
// //
this.textBox1.Location = new System.Drawing.Point(281, 92); this.naam.Location = new System.Drawing.Point(281, 92);
this.textBox1.Name = "textBox1"; this.naam.Name = "naam";
this.textBox1.Size = new System.Drawing.Size(100, 20); this.naam.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 0; this.naam.TabIndex = 0;
// //
// textBox2 // achternaam
// //
this.textBox2.Location = new System.Drawing.Point(281, 118); this.achternaam.Location = new System.Drawing.Point(281, 118);
this.textBox2.Name = "textBox2"; this.achternaam.Name = "achternaam";
this.textBox2.Size = new System.Drawing.Size(100, 20); this.achternaam.Size = new System.Drawing.Size(100, 20);
this.textBox2.TabIndex = 1; this.achternaam.TabIndex = 1;
// //
// textBox3 // adres
// //
this.textBox3.Location = new System.Drawing.Point(281, 145); this.adres.Location = new System.Drawing.Point(281, 145);
this.textBox3.Name = "textBox3"; this.adres.Name = "adres";
this.textBox3.Size = new System.Drawing.Size(100, 20); this.adres.Size = new System.Drawing.Size(100, 20);
this.textBox3.TabIndex = 2; this.adres.TabIndex = 2;
// //
// textBox4 // gsm
// //
this.textBox4.Location = new System.Drawing.Point(281, 170); this.gsm.Location = new System.Drawing.Point(281, 170);
this.textBox4.Name = "textBox4"; this.gsm.Name = "gsm";
this.textBox4.Size = new System.Drawing.Size(100, 20); this.gsm.Size = new System.Drawing.Size(100, 20);
this.textBox4.TabIndex = 3; this.gsm.TabIndex = 3;
// //
// textBox5 // balans
// //
this.textBox5.Location = new System.Drawing.Point(281, 196); this.balans.Location = new System.Drawing.Point(281, 196);
this.textBox5.Name = "textBox5"; this.balans.Name = "balans";
this.textBox5.Size = new System.Drawing.Size(100, 20); this.balans.Size = new System.Drawing.Size(100, 20);
this.textBox5.TabIndex = 4; this.balans.TabIndex = 4;
// //
// label1 // label1
// //
@@ -130,6 +130,7 @@
this.button1.TabIndex = 10; this.button1.TabIndex = 10;
this.button1.Text = "Toevoegen"; this.button1.Text = "Toevoegen";
this.button1.UseVisualStyleBackColor = true; this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.Button1_Click);
// //
// User // User
// //
@@ -142,11 +143,11 @@
this.Controls.Add(this.label3); this.Controls.Add(this.label3);
this.Controls.Add(this.label2); this.Controls.Add(this.label2);
this.Controls.Add(this.label1); this.Controls.Add(this.label1);
this.Controls.Add(this.textBox5); this.Controls.Add(this.balans);
this.Controls.Add(this.textBox4); this.Controls.Add(this.gsm);
this.Controls.Add(this.textBox3); this.Controls.Add(this.adres);
this.Controls.Add(this.textBox2); this.Controls.Add(this.achternaam);
this.Controls.Add(this.textBox1); this.Controls.Add(this.naam);
this.Name = "User"; this.Name = "User";
this.Text = "User"; this.Text = "User";
this.ResumeLayout(false); this.ResumeLayout(false);
@@ -156,11 +157,11 @@
#endregion #endregion
private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.TextBox naam;
private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.TextBox achternaam;
private System.Windows.Forms.TextBox textBox3; private System.Windows.Forms.TextBox adres;
private System.Windows.Forms.TextBox textBox4; private System.Windows.Forms.TextBox gsm;
private System.Windows.Forms.TextBox textBox5; private System.Windows.Forms.TextBox balans;
private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label3;

View File

@@ -1,4 +1,5 @@
using System; using Logic;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
@@ -12,14 +13,29 @@ namespace GUI_Gokkantoor
{ {
public partial class User : Form public partial class User : Form
{ {
LogicLayer l;
public User(Logic.LogicLayer l) public User(Logic.LogicLayer l)
{ {
InitializeComponent(); InitializeComponent();
this.l = l;
} }
private void label4_Click(object sender, EventArgs e) private void label4_Click(object sender, EventArgs e)
{ {
} }
private void Button1_Click(object sender, EventArgs e)
{
try
{
l.addPerson(new Globals.classes.Person(naam.Text, achternaam.Text, adres.Text, gsm.Text, double.Parse(balans.Text)));
l.save();
} catch (Exception ex)
{
// geen correcte double ingegeven wss. niet vergeten popup te schrijven.
}
}
} }
} }

View File

@@ -56,7 +56,7 @@ namespace Globals.classes
this.home.scoreChanged += homeSet; this.home.scoreChanged += homeSet;
this.away.scoreChanged += awaySet; this.away.scoreChanged += awaySet;
} }
public Game(int id, Ploeg home, Ploeg away, int scoreHome, int scoreAway) public Game(int id, PloegInMatch home, PloegInMatch away, int scoreHome, int scoreAway)
{ {
homeSetBool = false; homeSetBool = false;
awaySetBool = false; awaySetBool = false;

View File

@@ -35,8 +35,15 @@ namespace Globals.classes
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
Person p = (Person)obj; try
return this.Id == p.Id; {
Person p = (Person)obj;
return this.Id == p.Id;
} catch (Exception e)
{
return false;
}
} }
public override int GetHashCode() public override int GetHashCode()

View File

@@ -6,23 +6,20 @@ namespace Globals.classes
{ {
public class Ploeg : IPloeg public class Ploeg : IPloeg
{ {
public Ploeg(int id, string naam) public Ploeg(string naam)
{ {
Id = id;
this.naam = naam; this.naam = naam;
} }
public Ploeg(Ploeg p) public Ploeg(Ploeg p)
{ {
this.Id = p.Id;
this.naam = p.naam; this.naam = p.naam;
} }
public int Id { get; set; }
public string naam { get; set; } public string naam { get; set; }
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
return base.Equals(obj); return ((Ploeg)obj).naam == this.naam;
} }
public override string ToString() public override string ToString()

View File

@@ -9,26 +9,29 @@ namespace Globals.classes
{ {
public class PloegInMatch : Ploeg public class PloegInMatch : Ploeg
{ {
public PloegInMatch(int id, string naam) : base(id, naam) public int Id;
public PloegInMatch(int id, string naam) : base( naam)
{ {
this.Id = id;
} }
public PloegInMatch(int id, string naam, int score) : base(id, naam) public PloegInMatch(int id, string naam, int score) : base(naam)
{ {
this.Id = id;
setScore(score); setScore(score);
} }
public PloegInMatch(Ploeg p) : base(p) public PloegInMatch(Ploeg p, int id) : base(p)
{ {
this.Id = p.Id; this.Id = id;
this.naam = p.naam; this.naam = p.naam;
} }
public PloegInMatch(Ploeg p, int score) : base(p) public PloegInMatch(Ploeg p, int score, int id) : base(p)
{ {
this.Id = p.Id; this.Id = id;
this.naam = p.naam; this.naam = p.naam;
setScore(score); setScore(score);
@@ -46,6 +49,16 @@ namespace Globals.classes
this.scoreSet = true; this.scoreSet = true;
} }
public override bool Equals(object obj)
{
return base.Equals(obj);
}
public override string ToString()
{
if (this.scoreSet) return this.naam + ": " +this.score;
else return this.naam + ": NaN";
}
} }
} }

View File

@@ -35,21 +35,18 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Classes\PloegInMatch.cs" /> <Compile Include="Classes\PloegInMatch.cs" />
<Compile Include="MyClass.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Classes\Bet.cs" /> <Compile Include="Classes\Bet.cs" />
<Compile Include="Classes\Game.cs" /> <Compile Include="Classes\Game.cs" />
<Compile Include="Classes\Person.cs" /> <Compile Include="Classes\Person.cs" />
<Compile Include="Classes\Ploeg.cs" /> <Compile Include="Classes\Ploeg.cs" />
<Compile Include="Interfaces\IBet.cs" /> <Compile Include="Interfaces\IBet.cs" />
<Compile Include="Interfaces\IData.cs" />
<Compile Include="Interfaces\IGame.cs" /> <Compile Include="Interfaces\IGame.cs" />
<Compile Include="Interfaces\ILogic.cs" /> <Compile Include="Interfaces\ILogic.cs" />
<Compile Include="Interfaces\IPerson.cs" /> <Compile Include="Interfaces\IPerson.cs" />
<Compile Include="Interfaces\IPloeg.cs" /> <Compile Include="Interfaces\IPloeg.cs" />
<Compile Include="main.cs" /> <Compile Include="main.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup />
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>

View File

@@ -1,18 +0,0 @@
using System;
using System.Collections.Generic;
using Globals.classes;
namespace Globals.Interfaces
{
public interface IData
{
List<Person> getPersons();
List<Game> getGames();
List<Ploeg> getPloegen();
List<Bet> getBets();
void saveBets(List<Bet> b);
void saveGames(List<Game> g);
void savePloegen(List<Ploeg> p);
void savePersons(List<Person> p);
}
}

View File

@@ -6,24 +6,22 @@ namespace Globals.Interfaces
{ {
public interface ILogic public interface ILogic
{ {
List<Person> persons { get; set; }
List<Bet> bets { get; set; }
List<Ploeg> ploegen { get; set; }
List<Game> games { get; set; }
Person getPerson(int id);
Bet getBet(int id);
Ploeg getPloeg(int id);
Game getGame(int id);
void addPloeg(Ploeg p);
void addGame(Game g);
void addBet(Bet b); void addBet(Bet b);
void addGame(Game g);
void addPerson(Person p); void addPerson(Person p);
void addPloeg(Ploeg p);
void addPloegInMatch(PloegInMatch p);
Bet getBet(int id);
List<Bet> GetBets();
Game getGame(int id);
List<Game> GetGames();
Person getPerson(int id);
List<Person> GetPeople();
Ploeg getPloeg(string naam);
List<Ploeg> GetPloegen();
PloegInMatch GetPloegInMatch(int id);
List<PloegInMatch> GetPloegInMatches();
void save(); void save();
void updateGame(Game g);
void updatePerson(Person p);
Person getPersonByString(string s);
Ploeg getPloegByString(string s);
Game getGameByString(string s);
Bet getBetByString(string s);
} }
} }

View File

@@ -3,7 +3,6 @@ namespace Globals.Interfaces
{ {
public interface IPloeg public interface IPloeg
{ {
int Id { get; set; }
string naam { get; set; } string naam { get; set; }
} }
} }

View File

@@ -8,212 +8,118 @@ namespace Logic
{ {
public class LogicLayer : ILogic public class LogicLayer : ILogic
{ {
private dataLayer d; private dataLayer data;
private db d;
public LogicLayer() public LogicLayer()
{ {
d = new dataLayer(); data = new dataLayer();
persons = d.getPersons(); d = data.getDb();
bets = d.getBets(); if (d.games == null) d.games = new List<Game>();
ploegen = d.getPloegen(); if (d.ploegen == null) d.ploegen = new List<Ploeg>();
games = d.getGames(); if (d.persons == null) d.persons = new List<Person>();
if (games == null) games = new List<Game>(); if (d.bets == null) d.bets = new List<Bet>();
if (ploegen == null) ploegen = new List<Ploeg>(); if (d.ploegInMatches == null) d.ploegInMatches = new List<PloegInMatch>();
if (persons == null) persons = new List<Person>();
if (bets == null) bets = new List<Bet>();
}
public LogicLayer(bool testMode)
{
d = new dataLayer();
this.persons = new List<Person>();
Person p = new Person("beppe", "vanrolleghem", "123straat", "04877777", 5);
fixIds();
this.persons.Add(p);
}
public List<Person> persons { get ; set; }
public List<Bet> bets { get; set; }
public List<Ploeg> ploegen { get; set; }
public List<Game> games { get; set; }
private void fixIds()
{
int i = 0;
foreach(Person p in persons)
{
p.Id = i;
i++;
}
i = 0;
foreach(Bet b in bets)
{
b.Id = i;
i++;
}
i = 0;
foreach(Ploeg p in ploegen)
{
p.Id = i;
i++;
}
i = 0;
foreach(Game g in games)
{
g.Id = i;
i++;
}
} }
public void addBet(Bet b) public void addBet(Bet b)
{ {
bets.Add(b); d.bets.Add(b);
fixIds();
} }
public void addGame(Game g) public void addGame(Game g)
{ {
games.Add(g); d.games.Add(g);
fixIds();
} }
public void addPerson(Person p) public void addPerson(Person p)
{ {
persons.Add(p); d.persons.Add(p);
fixIds();
} }
public void addPloeg(Ploeg p) public void addPloeg(Ploeg p)
{ {
ploegen.Add(p); d.ploegen.Add(p);
fixIds(); }
public void addPloegInMatch(PloegInMatch p)
{
d.ploegInMatches.Add(p);
} }
public Bet getBet(int id) public Bet getBet(int id)
{ {
foreach(Bet b in bets) foreach(Bet b in d.bets)
{ {
if (b.Id == id) return b; if (b.Id == id) return b;
} }
throw new Exception("No bets found with that id"); throw new Exception("No bets found with that id");
} }
public List<Bet> GetBets()
{
return d.bets;
}
public Game getGame(int id) public Game getGame(int id)
{ {
foreach (Game b in games) foreach (Game b in d.games)
{ {
if (b.Id == id) return b; if (b.Id == id) return b;
} }
throw new Exception("No bets found with that id"); throw new Exception("No bets found with that id");
} }
public List<Game> GetGames()
{
return d.games;
}
public List<Person> GetPeople()
{
return d.persons;
}
public Person getPerson(int id) public Person getPerson(int id)
{ {
return persons.FindLast(x => id == x.Id); return d.persons.FindLast(x => id == x.Id); //lambda
} }
public List<Person> filter(List<Person> p) public Ploeg getPloeg(string naam)
{ {
return filter(p); foreach (Ploeg b in d.ploegen)
{
if (b.naam == naam) return b;
}
throw new Exception("No ploegen found with that naam");
} }
public Ploeg getPloeg(int id) public List<Ploeg> GetPloegen()
{ {
foreach (Ploeg b in ploegen) return d.ploegen;
}
public PloegInMatch GetPloegInMatch(int id)
{
foreach (PloegInMatch b in d.ploegInMatches)
{ {
if (b.Id == id) return b; if (b.Id == id) return b;
} }
throw new Exception("No bets found with that id"); throw new Exception("No ploegen found with that naam");
} }
public List<PloegInMatch> GetPloegInMatches()
{
return d.ploegInMatches;
}
public void save() public void save()
{ {
fixIds(); data.saveDb(d);
d.savePersons(persons);
d.savePloegen(ploegen);
d.saveGames(games);
d.saveBets(bets);
} }
public void updateGame(Game g)
{
foreach (Game ga in games)
{
if (ga.Id == g.Id)
{
ga.home = g.home;
ga.away = g.away;
}
}
updateBets();
updateBalances();
}
private void updateBets()
{
foreach (Bet b in bets)
{
Game g = games.Find(e => b.game.Id == e.Id);
b.game = g;
if (g.away.scoreSet && g.home.scoreSet) { b.finished = true; }
}
}
private void updateBalances()
{
foreach (Person p in persons)
{
foreach (Bet b in bets)
{
if (b.Equals(p) && b.finished) p.balance += b.getProfit();
}
}
}
public void updatePerson(Person p)
{
persons[persons.FindIndex(e => e.Id == p.Id)] = p;
}
public Person getPersonByString(string s)
{
foreach (Person p in persons)
{
if (p.ToString() == s)
{
return p;
}
}
throw new Exception("No person by that personString found");
}
public Ploeg getPloegByString(string s)
{
foreach (Ploeg p in ploegen)
{
if (p.ToString() == s) return p;
}
throw new Exception("No ploeg by that ploegString was found");
}
public Game getGameByString(string s)
{
foreach (Game g in games)
{
if (g.ToString() == s) return g;
}
throw new Exception("No game by that gameString found");
}
public Bet getBetByString(string s)
{
foreach (Bet b in bets)
{
if (b.ToString() == s) return b;
}
throw new Exception("No bet by that betString was found");
}
} }
} }