Opdracht 3a
This commit is contained in:
parent
198167c70e
commit
64338adb2f
@ -7,52 +7,11 @@ namespace OOP_Opdracht_CSharp_Alfa_2022.classes
|
||||
{
|
||||
class Game : Model
|
||||
{
|
||||
// Define class members
|
||||
|
||||
private Dictionary<int, string> table_data;
|
||||
private KeyValuePair<int, string> record;
|
||||
|
||||
// Define methods
|
||||
|
||||
// Define Getters and Setters
|
||||
|
||||
|
||||
// Table data get/set methods
|
||||
public Dictionary<int, string> getTableData()
|
||||
{
|
||||
return this.table_data;
|
||||
}
|
||||
public void setTableData(Dictionary<int, string> table_data)
|
||||
{
|
||||
this.table_data = table_data;
|
||||
return;
|
||||
}
|
||||
// Record get/set methods
|
||||
public void setRecord(int key, string value)
|
||||
{
|
||||
var record = new KeyValuePair<int, string>(key, value);
|
||||
return;
|
||||
}
|
||||
// Overload in case of previously instantiated KeyValuePair as parameter
|
||||
public void setRecord(KeyValuePair<int, string> keyValuePair)
|
||||
{
|
||||
this.setRecord(keyValuePair.Key, keyValuePair.Value);
|
||||
return;
|
||||
}
|
||||
public KeyValuePair<int, string> getRecord()
|
||||
{
|
||||
return this.record;
|
||||
}
|
||||
// Get KeyValuePair by id, returns [-1, "Invalid Record"] when out of bounds
|
||||
public KeyValuePair<int, string> find(int id = 1)
|
||||
{
|
||||
KeyValuePair<int, string> record = new KeyValuePair<int, string>(-1, "Invalid Record");
|
||||
if (this.table_data.ContainsKey(id))
|
||||
{
|
||||
record = new KeyValuePair<int, string>(id, this.table_data.GetValueOrDefault(id));
|
||||
}
|
||||
this.record = record;
|
||||
return record;
|
||||
}
|
||||
// Game class constructor
|
||||
public Game()
|
||||
{
|
||||
|
||||
@ -7,7 +7,49 @@ namespace OOP_Opdracht_CSharp_Alfa_2022.classes
|
||||
{
|
||||
abstract class Model
|
||||
{
|
||||
private SqlConnection connection;
|
||||
protected SqlConnection connection;
|
||||
protected Dictionary<int, string> table_data;
|
||||
protected KeyValuePair<int, string> record;
|
||||
|
||||
// Define Getters and Setters
|
||||
|
||||
// Table data get/set methods
|
||||
public Dictionary<int, string> getTableData()
|
||||
{
|
||||
return this.table_data;
|
||||
}
|
||||
public void setTableData(Dictionary<int, string> table_data)
|
||||
{
|
||||
this.table_data = table_data;
|
||||
return;
|
||||
}
|
||||
// Record get/set methods
|
||||
public void setRecord(int key, string value)
|
||||
{
|
||||
var record = new KeyValuePair<int, string>(key, value);
|
||||
return;
|
||||
}
|
||||
// Overload in case of previously instantiated KeyValuePair as parameter
|
||||
public void setRecord(KeyValuePair<int, string> keyValuePair)
|
||||
{
|
||||
this.setRecord(keyValuePair.Key, keyValuePair.Value);
|
||||
return;
|
||||
}
|
||||
public KeyValuePair<int, string> getRecord()
|
||||
{
|
||||
return this.record;
|
||||
}
|
||||
|
||||
// Get KeyValuePair by id, returns [-1, "Invalid Record"] when out of bounds
|
||||
public KeyValuePair<int, string> find(int id = 1)
|
||||
{
|
||||
KeyValuePair<int, string> record = new KeyValuePair<int, string>(-1, "Invalid Record");
|
||||
if (this.table_data.ContainsKey(id))
|
||||
{
|
||||
record = new KeyValuePair<int, string>(id, this.table_data.GetValueOrDefault(id));
|
||||
}
|
||||
this.record = record;
|
||||
return record;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,5 +6,10 @@ namespace OOP_Opdracht_CSharp_Alfa_2022.classes
|
||||
{
|
||||
class Publisher : Model
|
||||
{
|
||||
public Publisher()
|
||||
{
|
||||
if (table_data == null) table_data = new Dictionary<int, string>();
|
||||
table_data.Add(1, "Electornic Arts");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user