Commit c96ed50d authored by NEBOIT Jean-Charles's avatar NEBOIT Jean-Charles
Browse files

Update BusinessLayer

parent 6e19fef6
......@@ -21,42 +21,47 @@ namespace BusinessLayer
public List<House> HousesList()
{
/*List<House> list = DalManager.HousesList();
return list.Select(House => House.Name + " has " + House.NbUnits + " Units.").ToList();*/
return DalManager.HousesList();
}
public List<House> HousesList(int sup)
{
/*List<House> list = DalManager.HousesList(sup);
return list.Select(House => House.Name).ToList();*/
return DalManager.HousesList(sup);
}
public House getHouseById(int id)
{
return DalManager.getHouseById(id);
}
public List<Characteristics> CharactersCharacteristicsList()
{
/*List<Characteristics> list = DalManager.CharactersCharacteristicsList();
return list.Select(c => "PV -> " + c.PV + ", Type -> " + c.Type + ", Bravoury -> " + c.Bravoury + ", Crazyness -> " + c.Crazyness).ToList();*/
return DalManager.CharactersCharacteristicsList();
}
public List<Character> CharactersList()
{
/*List<Character> list = DalManager.CharactersList();
return list.Select(c => c.FirstName + " " + c.LastName).ToList();*/
return DalManager.CharactersList();
}
public List<Character> CharactersList(int BravourySup, int PVSup)
{
/*List<Character> list = DalManager.CharactersList();
return list.Where(c => c.Characteristics.Bravoury > BravourySup && c.Characteristics.PV > PVSup).Select(c => c.FirstName + " " + c.LastName).ToList();*/
return DalManager.CharactersList().Where(c => c.Characteristics.Bravoury > BravourySup && c.Characteristics.PV > PVSup).ToList();
}
public List<Territory> TerritoryList()
{
/*List<Territory> list = DalManager.TerritoriesList();
return list.Select(t => t.Type + " owned by " + t.Owner.Name).ToList();*/
return DalManager.TerritoriesList();
}
public void addCharacter(Character c)
{
DalManager.addCharacter(c);
}
public void deleteCharacater(int id)
{
DalManager.deleteCharacter(id);
}
public void updateCharacter(Character c)
{
DalManager.updateCharacter(c);
}
}
}
......@@ -47,6 +47,10 @@ namespace DataAccessLayer
return dataBaseBridge.HousesList(sup);
}
public House getHouseById(int id)
{
return dataBaseBridge.getHouseById(id);
}
public List<Characteristics> CharactersCharacteristicsList()
{
return dataBaseBridge.CharactersCharacteristicsList();
......
......@@ -11,6 +11,7 @@ namespace DataAccessLayer
{
List<House> HousesList();
List<House> HousesList(int sup);
House getHouseById(int id);
List<Character> CharactersList();
List<Characteristics> CharactersCharacteristicsList();
List<Territory> TerritoriesList();
......
......@@ -27,7 +27,7 @@ namespace DataAccessLayer
}
catch (SqlException e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
}
......@@ -128,6 +128,14 @@ namespace DataAccessLayer
return res;
}
public House getHouseById(int id)
{
DataTable houseData = SelectByDataAdapter("Select * From House Where Id=" + id);
DataRow houseRow = houseData.Rows[0];
House res = new House(Convert.ToInt32(houseRow["Id"]), houseRow["name"].ToString(), Convert.ToInt32(houseRow["nbUnits"]));
return res;
}
public List<Territory> TerritoriesList()
{
......@@ -151,7 +159,7 @@ namespace DataAccessLayer
public void addCharacter(Character character)
{
SelectByDataAdapter("INSERT INTO Character VALUES('" + character.FirstName + "','" + character.LastName + "'," + character.Characteristics.PV + "," + character.Characteristics.Type + "," + character.Characteristics.Bravoury + "," + character.Characteristics.Crazyness + "," + character.House.ID);
SelectByDataAdapter("INSERT INTO Character VALUES('" + character.FirstName + "','" + character.LastName + "'," + character.Characteristics.PV + "," + (int)character.Characteristics.Type + "," + character.Characteristics.Bravoury + "," + character.Characteristics.Crazyness + "," + character.House.ID +")");
}
public void deleteCharacter(int id)
......@@ -162,7 +170,16 @@ namespace DataAccessLayer
public void updateCharacter(Character character)
{
String request = "Select * From Character Where Id=" + character.ID;
DataTable dataTable = SelectByDataAdapter(request);
dataTable.Rows[0]["FirstName"] = character.FirstName;
dataTable.Rows[0]["LastName"] = character.LastName;
dataTable.Rows[0]["PV"] = character.Characteristics.PV;
dataTable.Rows[0]["Type"] = character.Characteristics.Type;
dataTable.Rows[0]["Bravoury"] = character.Characteristics.Bravoury;
dataTable.Rows[0]["Crazyness"] = character.Characteristics.Crazyness;
dataTable.Rows[0]["id_house"] = character.House.ID;
UpdateByCommandBuilder(request, dataTable);
}
}
}
No preview for this file type
No preview for this file type
......@@ -11,58 +11,67 @@ namespace ThronesTournamentConsole
{
BusinessLayer.ThronesTournamentManager businessLayer = new BusinessLayer.ThronesTournamentManager();
/*public void DisplayHouses()
public void DisplayHouses()
{
Console.WriteLine("---- Display Houses ----");
List<String> _listHouse = businessLayer.HousesList();
List<String> _listHouse = businessLayer.HousesList().Select(House => House.Name + " has " + House.NbUnits + " Units.").ToList();
for (int k = 0; k < _listHouse.Count(); k++)
Console.WriteLine(_listHouse[k]);
}
public void DisplayHouses(int sup)
{
Console.WriteLine("---- Display Houses with Units > " + sup + " ----");
List<String> _listHouse = businessLayer.HousesList(sup);
List<String> _listHouse = businessLayer.HousesList(sup).Select(House => House.Name).ToList();
for (int k = 0; k < _listHouse.Count(); k++)
Console.WriteLine(_listHouse[k]);
}
public void DisplayCharacteristics()
{
Console.WriteLine("---- Display Characteristics ----");
foreach (String s in businessLayer.CharactersCharacteristicsList())
foreach (String s in businessLayer.CharactersCharacteristicsList().Select(c => "PV -> " + c.PV + ", Type -> " + c.Type + ", Bravoury -> " + c.Bravoury + ", Crazyness -> " + c.Crazyness).ToList())
Console.WriteLine(s);
}
public void DisplayCharacters()
{
Console.WriteLine("---- Display Characters ----");
foreach (String s in businessLayer.CharactersList())
foreach (String s in businessLayer.CharactersList().Select(c => c.FirstName + " " + c.LastName).ToList())
Console.WriteLine(s);
}
public void DisplayCharacters(int BravourySup, int PVSup)
{
Console.WriteLine("---- Display Characters with Bravoury > " + BravourySup + " and Pv > " + PVSup + " ----");
foreach (String s in businessLayer.CharactersList(BravourySup, PVSup))
foreach (String s in businessLayer.CharactersList(BravourySup, PVSup).Select(c => c.FirstName + " " + c.LastName).ToList())
Console.WriteLine(s);
}
public void DisplayTerritories()
{
Console.WriteLine("---- Display Territories ----");
List<String> terr = businessLayer.TerritoryList();
List<String> terr = businessLayer.TerritoryList().Select(t => t.Type + " owned by " + t.Owner.Name).ToList();
for (int k = 0; k < terr.Count(); k++)
Console.WriteLine(terr[k]);
}*/
}
public void addCharacter()
{
House house = businessLayer.getHouseById(1);
Console.WriteLine(house.Name);
businessLayer.addCharacter(new Character("Robb", "Stark", 100, CharacterType.LEADER, 90, 20, house));
}
static void Main(string[] args)
{
Program game = new Program();
/*game.DisplayHouses();
game.DisplayHouses();
game.DisplayHouses(200);
game.DisplayCharacteristics();
game.DisplayTerritories();
game.DisplayCharacters();
game.DisplayCharacters(30, 50);*/
game.DisplayCharacters(30, 50);
game.addCharacter();
game.DisplayCharacters();
Console.ReadKey();
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment