Commit 359710b1 authored by julescournut's avatar julescournut
Browse files

Fix Relationship

parent 8b073f2b
......@@ -11,7 +11,7 @@ namespace DataAccessLayer
{
List<House> HousesList();
List<House> HousesList(int sup);
Dictionary<Character, RelationshipType> RelationShipList(int id);
List<RelationShip> RelationShipList(int id);
List<Character> CharactersList();
List<Characteristics> CharactersCharacteristicsList();
List<Territory> TerritoriesList();
......
......@@ -68,9 +68,9 @@ namespace DataAccessLayer
return result;
}
public Dictionary<Character, RelationshipType> RelationShipList(int id)
public List<RelationShip> RelationShipList(int id)
{
Dictionary<Character, RelationshipType> res = new Dictionary<Character, RelationshipType>();
List<RelationShip> res = new List<RelationShip>();
try
{
DataTable dataTable = SelectByDataAdapter("Select * From Relationship Where id_charach1 = " + id + " OR id_charach2 = " + id);
......@@ -83,7 +83,7 @@ namespace DataAccessLayer
id_character = Convert.ToInt32(row["id_charach2"]);
}
Character character = getCharacterById(id_character);
res.Add(character, (RelationshipType)Convert.ToInt32(row["type"]));
res.Add(new RelationShip(character, (RelationshipType)Convert.ToInt32(row["type"])));
}
}
catch (Exception e)
......@@ -104,7 +104,7 @@ namespace DataAccessLayer
{
int id_house = Convert.ToInt32(row["id_house"]);
House house = getHouseById(id_house);
Character character = new Character(Convert.ToInt32(row["Id"]), row["FirstName"].ToString(), row["LastName"].ToString(), Convert.ToUInt32(row["PV"]), (CharacterType)Convert.ToInt32(row["Type"]), Convert.ToInt32(row["Bravoury"]), Convert.ToInt32(row["Crazyness"]), house/*, RelationShipList(Convert.ToInt32(row["Id"]))*/);
Character character = new Character(Convert.ToInt32(row["Id"]), row["FirstName"].ToString(), row["LastName"].ToString(), Convert.ToUInt32(row["PV"]), (CharacterType)Convert.ToInt32(row["Type"]), Convert.ToInt32(row["Bravoury"]), Convert.ToInt32(row["Crazyness"]), house, RelationShipList(Convert.ToInt32(row["Id"])));
res.Add(character);
}
}
......
No preview for this file type
No preview for this file type
......@@ -37,7 +37,7 @@ namespace EntitiesLayer
public string LastName { get; set; }
public Characteristics Characteristics { get; set; }
public House House { get; set; }
public Dictionary<Character, RelationshipType> RelationShips { get; set; }
public List<RelationShip> RelationShips { get; set; }
public Character(string firstName, string lastName, uint pv, CharacterType type, int bravoury, int crazyness, House house)
{
......@@ -46,7 +46,7 @@ namespace EntitiesLayer
LastName = lastName;
Characteristics = new Characteristics(pv, type, bravoury, crazyness);
House = house;
RelationShips = new Dictionary<Character, RelationshipType>();
RelationShips = new List<RelationShip>();
}
public Character(int id, string firstName, string lastName, uint pv, CharacterType type, int bravoury, int crazyness, House house)
......@@ -56,10 +56,10 @@ namespace EntitiesLayer
LastName = lastName;
Characteristics = new Characteristics(pv, type, bravoury, crazyness);
House = house;
RelationShips = new Dictionary<Character, RelationshipType>();
RelationShips = new List<RelationShip>();
}
public Character(int id, string firstName, string lastName, uint pv, CharacterType type, int bravoury, int crazyness, House house, Dictionary<Character, RelationshipType> relationShips) : this(id, firstName, lastName, pv, type, bravoury, crazyness, house)
public Character(int id, string firstName, string lastName, uint pv, CharacterType type, int bravoury, int crazyness, House house, List<RelationShip> relationShips) : this(id, firstName, lastName, pv, type, bravoury, crazyness, house)
{
RelationShips = relationShips;
}
......@@ -67,7 +67,7 @@ namespace EntitiesLayer
public void AddRelatives(Character c, RelationshipType rel)
{
RelationShips.Add(c, rel);
RelationShips.Add(new RelationShip(c, rel));
}
public override string ToString()
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntitiesLayer
{
public enum RelationshipType
{
FRIENDSHIP,
LOVE,
HATRED,
RIVALRY
}
public class RelationShip
{
public Character Character { get; set; }
public RelationshipType Type { get; set; }
public RelationShip(Character character, RelationshipType type)
{
Character = character;
Type = type;
}
}
}
......@@ -206,6 +206,7 @@
</Compile>
<Compile Include="Models\AccountViewModels.cs" />
<Compile Include="Models\CharacterModels.cs" />
<Compile Include="Models\RelationShipModels.cs" />
<Compile Include="Models\TerritoryModels.cs" />
<Compile Include="Models\WarModels.cs" />
<Compile Include="Models\FightModels.cs" />
......
......@@ -5,14 +5,6 @@ using System.Web;
namespace MVC.Models
{
public enum RelationshipType
{
FRIENDSHIP,
LOVE,
HATRED,
RIVALRY
}
public enum CharacterType
{
WARRIOR,
......@@ -53,7 +45,7 @@ namespace MVC.Models
public string LastName { get; set; }
public HouseModels House { get; set; }
public CharacteristicsModels Characteristics { get; set; }
public Dictionary<CharacterModels, RelationshipType> RelationShips { get; set; }
public List<RelationShipModels> RelationShips { get; set; }
public CharacterModels()
{
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MVC.Models
{
public enum RelationshipType
{
FRIENDSHIP,
LOVE,
HATRED,
RIVALRY
}
public class RelationShipModels
{
public CharacterModels Character { get; set; }
public RelationshipType Type { get; set; }
public RelationShipModels(CharacterModels character, RelationshipType type)
{
Character = character;
Type = type;
}
}
}
\ No newline at end of file
......@@ -45,10 +45,10 @@
<td>
@foreach (var rel in item.RelationShips) {
<td>
@Html.DisplayFor(modelItem => rel.Value))
@Html.DisplayFor(modelItem => rel.Character))
</td>
<td>
@Html.DisplayFor(modelItem => rel.Key.FirstName + rel.Key.LastName))
@Html.DisplayFor(modelItem => rel.Type))
</td>
}
</td>
......
@model IEnumerable<MVC.Models.TerritoryModels>
@{
ViewBag.Title = "Territory List";
}
<h2>@ViewBag.Title</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Owner)
</th>
<th>
@Html.DisplayNameFor(model => model.Type)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Owner.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Type)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
}
</table>
@model IEnumerable<MVC.Models.WarModels>
@{
ViewBag.Title = "War List";
}
<h2>@ViewBag.Title</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
}
</table>
using System;
using System.Collections.Generic;
using System.Linq;
using WebApiGOT.Models;
using BusinessLayer;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace WebApiGOT.Controllers
{
public class TerritoryController : ApiController
{
// GET: api/Territory
public List<TerritoryDTO> GetAllHouse()
{
List<TerritoryDTO> list = new List<TerritoryDTO>();
BusinessLayer.ThronesTournamentManager busi = new BusinessLayer.ThronesTournamentManager();
foreach (EntitiesLayer.Territory territory in busi.TerritoryList())
{
list.Add(new TerritoryDTO(territory));
}
return list;
}
// GET: api/Territory/5
public TerritoryDTO Get(int id)
{
BusinessLayer.ThronesTournamentManager busi = new BusinessLayer.ThronesTournamentManager();
return new TerritoryDTO(busi.getTerritoryById(id));
}
// POST: api/Territory
public void Post([FromBody]string value)
{
}
// PUT: api/Territory/5
public void Put(int id, [FromBody]string value)
{
}
// DELETE: api/Territory/5
public void Delete(int id)
{
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using WebApiGOT.Models;
using BusinessLayer;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace WebApiGOT.Controllers
{
public class WarController : ApiController
{
// GET: api/War
public List<WarDTO> GetAllWar()
{
List<WarDTO> list = new List<WarDTO>();
BusinessLayer.ThronesTournamentManager busi = new BusinessLayer.ThronesTournamentManager();
foreach (EntitiesLayer.War war in busi.WarList())
{
list.Add(new WarDTO(war));
}
return list;
}
// GET: api/War/2
public WarDTO Get(int id)
{
BusinessLayer.ThronesTournamentManager busi = new BusinessLayer.ThronesTournamentManager();
return new WarDTO(busi.getWarById(id));
}
// POST: api/War
public void Post([FromBody]string value)
{
}
// PUT: api/War/2
public void Put(int id, [FromBody]string value)
{
}
// DELETE: api/War/2
public void Delete(int id)
{
}
}
}
......@@ -28,7 +28,7 @@ namespace WebApiGOT.Models
public string LastName { get; set; }
public HouseDTO House { get; set; }
public CharacteristicsDTO Characteristics { get; set; }
public Dictionary<CharacterDTO, RelationshipType> RelationShips { get; set; }
public List<RelationShipDTO> RelationShips { get; set; }
public CharacterDTO(Character c)
{
......@@ -36,10 +36,10 @@ namespace WebApiGOT.Models
LastName = c.LastName;
House = new HouseDTO(c.House);
Characteristics = new CharacteristicsDTO(c.Characteristics);
RelationShips = new Dictionary<CharacterDTO, RelationshipType>();
RelationShips = new List<RelationShipDTO>();
foreach(var r in c.RelationShips)
{
RelationShips.Add(new CharacterDTO(r.Key), r.Value);
RelationShips.Add(new RelationShipDTO(new CharacterDTO(r.Character), r.Type));
}
}
}
......
using EntitiesLayer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebApiGOT.Models
{
public class RelationShipDTO
{
public CharacterDTO Character { get; set; }
public RelationshipType Type { get; set; }
public RelationShipDTO(CharacterDTO character, RelationshipType type)
{
Character = character;
Type = type;
}
}
}
\ No newline at end of file
using EntitiesLayer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebApiGOT.Models
{
public class TerritoryDTO
{
public TerritoryType Type { get; set; }
public HouseDTO Owner { get; set; }
public TerritoryDTO(Territory t)
{
Type = t.Type;
Owner = new HouseDTO(t.Owner);
}
}
}
\ No newline at end of file
......@@ -154,6 +154,7 @@
<DependentUpon>Global.asax</DependentUpon>
</Compile>
<Compile Include="Models\CharacterDTO.cs" />
<Compile Include="Models\RelationShipDTO.cs" />
<Compile Include="Models\TerritoryDTO.cs" />
<Compile Include="Models\FightDTO.cs" />
<Compile Include="Models\HouseDTO.cs" />
......
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