Commit 219c65ec authored by julescournut's avatar julescournut
Browse files

Add Territory to Fight

parent 671fce53
......@@ -64,6 +64,11 @@ namespace BusinessLayer
return DalManager.getFightById(id);
}
public List<Fight> getFightbyWarID(int id)
{
return DalManager.getFightbyWarID(id);
}
public List<Characteristics> CharactersCharacteristicsList()
{
return DalManager.CharactersCharacteristicsList();
......
......@@ -77,6 +77,10 @@ namespace DataAccessLayer
return dataBaseBridge.getFightById(id);
}
public List<Fight> getFightbyWarID(int id)
{
return dataBaseBridge.getFightbyWarID(id);
}
public List<Characteristics> CharactersCharacteristicsList()
{
return dataBaseBridge.CharactersCharacteristicsList();
......
......@@ -23,6 +23,7 @@ namespace DataAccessLayer
War getWarById(int id);
Territory getTerritoryById(int id);
Fight getFightById(int id);
List<Fight> getFightbyWarID(int id);
int addCharacter(Character character);
void deleteCharacter(int id);
......
......@@ -12,9 +12,9 @@ namespace DataAccessLayer
{
class SqlServer : DataBaseBridge
{
private string _connectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=H:\\ServiceWeb\\Database\\db.mdf;Integrated Security=True;Connect Timeout=30";
//private string _connectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=H:\\ServiceWeb\\Database\\db.mdf;Integrated Security=True;Connect Timeout=30";
//private string _connectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\NEBOIT\\Documents\\GitHub\\ServiceWeb\\Database\\db.mdf;Integrated Security=True;Connect Timeout=30";
//private string _connectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\JULES\\DOCUMENTS\\ISIMA\\2ÈME ANNÉE\\SERVICEWEB\\DATABASE\\DB.MDF;Integrated Security=True;Connect Timeout=30";
private string _connectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\JULES\\DOCUMENTS\\ISIMA\\2ÈME ANNÉE\\SERVICEWEB\\DATABASE\\DB.MDF;Integrated Security=True;Connect Timeout=30";
private void LogException(Exception e)
{
......@@ -156,7 +156,10 @@ namespace DataAccessLayer
int id_winner = (row["id_winner"] is DBNull) ? -1 : Convert.ToInt32(row["id_winner"]);
House winner = (id_winner == -1) ? null : getHouseById(id_winner);
Fight fight = new Fight(Convert.ToInt32(row["Id"]), row["name"].ToString(), chal1, chal2, winner, war);
int id_territory = Convert.ToInt32(row["id_territory"]);
Territory territory = getTerritoryById(id_territory);
Fight fight = new Fight(Convert.ToInt32(row["Id"]), row["name"].ToString(), chal1, chal2, winner, war, territory);
res.Add(fight);
}
}
......@@ -278,16 +281,52 @@ namespace DataAccessLayer
Fight res = null;
try
{
DataTable territoryData = SelectByDataAdapter("Select * From Fight Where Id=" + id);
DataRow territoryRow = territoryData.Rows[0];
int id_house1 = Convert.ToInt32(territoryRow["id_challenger1"]);
DataTable fightData = SelectByDataAdapter("Select * From Fight Where Id=" + id);
DataRow fightRow = fightData.Rows[0];
int id_house1 = Convert.ToInt32(fightRow["id_challenger1"]);
House house1 = getHouseById(id_house1);
int id_house2 = Convert.ToInt32(territoryRow["id_challenger2"]);
int id_house2 = Convert.ToInt32(fightRow["id_challenger2"]);
House house2 = getHouseById(id_house2);
int id_winner = Convert.ToInt32(territoryRow["id_winner"]);
int id_war = Convert.ToInt32(territoryRow["id_war"]);
int id_winner = Convert.ToInt32(fightRow["id_winner"]);
int id_war = Convert.ToInt32(fightRow["id_war"]);
War war = getWarById(id_war);
res = new Fight(territoryRow["name"].ToString(), house1, house2, (id_winner == house1.ID) ? house1 : house2, war);
int id_territory = Convert.ToInt32(fightRow["id_territory"]);
Territory territory = getTerritoryById(id_territory);
res = new Fight(fightRow["name"].ToString(), house1, house2, (id_winner == house1.ID) ? house1 : house2, war, territory);
}
catch (Exception e)
{
LogException(e);
}
return res;
}
public List<Fight> getFightbyWarID(int id)
{
List<Fight> res = new List<Fight>();
try
{
DataTable dataTable = SelectByDataAdapter("Select * From Fight Where id_war = " + id);
foreach (DataRow row in dataTable.Rows)
{
int id_house = Convert.ToInt32(row["id_challenger1"]);
House chal1 = getHouseById(id_house);
id_house = Convert.ToInt32(row["id_challenger2"]);
House chal2 = getHouseById(id_house);
int id_war = (row["id_war"] is DBNull) ? -1 : Convert.ToInt32(row["id_war"]);
War war = (id_war == -1) ? null : getWarById(id_war);
int id_winner = (row["id_winner"] is DBNull) ? -1 : Convert.ToInt32(row["id_winner"]);
House winner = (id_winner == -1) ? null : getHouseById(id_winner);
int id_territory = Convert.ToInt32(row["id_territory"]);
Territory territory = getTerritoryById(id_territory);
Fight fight = new Fight(Convert.ToInt32(row["Id"]), row["name"].ToString(), chal1, chal2, winner, war, territory);
res.Add(fight);
}
}
catch (Exception e)
{
......@@ -373,7 +412,7 @@ namespace DataAccessLayer
}
public int addFight(Fight fight)
{
DataTable fightData = SelectByDataAdapter("INSERT INTO Fight VALUES('" + fight.Name + "'," + fight.Challenger1.ID + "," + fight.Challenger2.ID + "," + fight.Winner.ID + "," + fight.War.ID + "); SELECT SCOPE_IDENTITY() AS ID");
DataTable fightData = SelectByDataAdapter("INSERT INTO Fight VALUES('" + fight.Name + "'," + fight.Challenger1.ID + "," + fight.Challenger2.ID + "," + fight.Winner.ID + "," + fight.War.ID + "," + fight.Territory.ID + "); SELECT SCOPE_IDENTITY() AS ID");
return (fightData.Rows.Count == 1) ? Convert.ToInt32(fightData.Rows[0]["ID"]) : -1;
}
......@@ -393,6 +432,7 @@ namespace DataAccessLayer
dataTable.Rows[0]["id_challenger2"] = fight.Challenger2.ID;
dataTable.Rows[0]["id_winner"] = fight.Winner.ID;
dataTable.Rows[0]["id_war"] = fight.War.ID;
dataTable.Rows[0]["id_territory"] = fight.Territory.ID;
UpdateByCommandBuilder(request, dataTable);
}
}
......
No preview for this file type
No preview for this file type
......@@ -13,8 +13,9 @@ namespace EntitiesLayer
public House Challenger2 { get; set; }
public House Winner { get; set; }
public War War { get; set; }
public Territory Territory { get; set; }
public Fight(String name, House challenger1, House challenger2, War war)
public Fight(String name, House challenger1, House challenger2, War war, Territory territory)
{
ID = 0;
Name = name;
......@@ -29,18 +30,20 @@ namespace EntitiesLayer
Winner = challenger2;
}
War = war;
Territory = territory;
}
public Fight(String name, House challenger1, House challenger2, House winner, War war)
public Fight(String name, House challenger1, House challenger2, House winner, War war, Territory territory)
{
Name = name;
Challenger1 = challenger1;
Challenger2 = challenger2;
Winner = winner;
War = war;
Territory = territory;
}
public Fight(int id, String name, House challenger1, House challenger2, House winner, War war)
public Fight(int id, String name, House challenger1, House challenger2, House winner, War war, Territory territory)
{
ID = id;
Name = name;
......@@ -48,6 +51,7 @@ namespace EntitiesLayer
Challenger2 = challenger2;
Winner = winner;
War = war;
Territory = territory;
}
}
}
......@@ -115,6 +115,7 @@ namespace MVC.Controllers
}
}
perso.Characteristics.Type = collection.Characteristics.Type;
perso.Characteristics.PV = collection.Characteristics.PV;
perso.Characteristics.Bravoury = collection.Characteristics.Bravoury;
perso.Characteristics.Crazyness = collection.Characteristics.Crazyness;
......
......@@ -80,6 +80,24 @@ namespace MVC.Controllers
Text = w.Name,
Value = w.ID.ToString()
});
List<TerritoryModels> territories = new List<TerritoryModels>();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:13666/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync("api/territory");
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
territories = JsonConvert.DeserializeObject<List<TerritoryModels>>(temp);
}
}
ViewBag.ListTerritories = territories.Select(h => new SelectListItem()
{
Text = h.Name,
Value = h.ID.ToString()
});
return View();
}
......@@ -131,6 +149,20 @@ namespace MVC.Controllers
}
}
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:13666/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync("api/territory/" + collection.Territory.ID);
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
fight.Territory = JsonConvert.DeserializeObject<TerritoryModels>(temp);
}
}
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:13666/");
......
......@@ -112,9 +112,22 @@ namespace MVC.Controllers
}
}
// POST: House/Delete/5
public ActionResult Delete(int id)
public async Task<ActionResult> Delete(int id)
{
return View();
HouseModels house = new HouseModels();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:13666/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync("api/house/" + id);
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
house = JsonConvert.DeserializeObject<HouseModels>(temp);
}
}
return View(house);
}
// POST: Fight/Delete/2
......
......@@ -45,7 +45,7 @@ namespace MVC.Controllers
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync("api/Fight");
HttpResponseMessage response = await client.GetAsync("api/war/fight/" + id);
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
......@@ -129,9 +129,22 @@ namespace MVC.Controllers
}
// GET: War/Delete/1
public ActionResult Delete(int id)
public async Task<ActionResult> Delete(int id)
{
return View();
WarModels war = new WarModels();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:13666/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync("api/war/" + id);
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
war = JsonConvert.DeserializeObject<WarModels>(temp);
}
}
return View(war);
}
// POST: Fight/Delete/2
......
......@@ -295,7 +295,6 @@
<Content Include="Views\Fight\Delete.cshtml" />
<Content Include="Views\Character\Edit.cshtml" />
<Content Include="Views\Character\Details.cshtml" />
<Content Include="Views\Fight\Edit.cshtml" />
<Content Include="Views\Fight\Create.cshtml" />
<Content Include="Views\War\Details.cshtml" />
<Content Include="Views\Territory\Edit.cshtml" />
......
......@@ -7,12 +7,13 @@ namespace MVC.Models
{
public class FightModels
{
public int ID;
public int ID { get; set; }
public String Name { get; set; }
public HouseModels Challenger1 { get; set; }
public HouseModels Challenger2 { get; set; }
public HouseModels Winner { get; set; }
public WarModels War { get; set; }
public TerritoryModels Territory { get; set; }
public FightModels()
{
......@@ -22,6 +23,7 @@ namespace MVC.Models
Challenger2 = new HouseModels();
Winner = new HouseModels();
War = new WarModels();
}
Territory = new TerritoryModels();
}
}
}
\ No newline at end of file
......@@ -48,6 +48,14 @@
@Html.ActionLink("Create new war", "../War/Create")
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Territory, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.Territory.ID, ViewBag.ListTerritories as IEnumerable<SelectListItem>, "", new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Territory, "", new { @class = "text-danger" })
@Html.ActionLink("Create new territory", "../Territory/Create")
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
......
@model MVC.Models.CharacterModels
@{
ViewBag.Title = "Edit";
}
<h2>@ViewBag.Title @Model.Name</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.FirstName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.FirstName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.LastName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.LastName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.LastName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.House, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.House.ID, ViewBag.ListHouses as IEnumerable<SelectListItem>, "", new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.House, "", new { @class = "text-danger" })
@Html.ActionLink("Create new house", "../House/Create")
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Characteristics.PV, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Characteristics.PV, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Characteristics.PV, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Characteristics.Type, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EnumDropDownListFor( model => model.Characteristics.Type, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Characteristics.Bravoury, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Characteristics.Bravoury, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Characteristics.Bravoury, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Characteristics.Crazyness, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Characteristics.Crazyness, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Characteristics.Crazyness, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
......@@ -26,6 +26,9 @@
<th>
@Html.DisplayNameFor(model => model.War)
</th>
<th>
@Html.DisplayNameFor(model => model.Territory)
</th>
</tr>
@foreach (var item in Model)
......@@ -46,6 +49,9 @@
<td>
@Html.DisplayFor(modelItem => item.War.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Territory.Name)
</td>
<td>
@Html.ActionLink("Delete", "Delete", new { id=item.ID })
</td>
......
@model MVC.Models.HouseModels
@{
ViewBag.Title = "Create";
ViewBag.Title = "Create House";
}
<h2>Create</h2>
<h2>@ViewBag.Title</h2>
@using (Html.BeginForm())
......@@ -12,7 +12,6 @@
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>HouseModels</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
......
......@@ -4,7 +4,7 @@
ViewBag.Title = "Delete";
}
<h3>Are you sure you want to delete this house ?</h3>
<h3>Are you sure you want to delete the @Model.Name House ?</h3>
<div>
<hr />
......
......@@ -4,10 +4,8 @@
ViewBag.Title = "Delete";
}
<h3>Are you sure you want to delete this?</h3>
<h3>Are you sure you want to delete @Model.Name?</h3>
<div>
<h4>TerritoryModels</h4>
<hr />
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
......
@model IEnumerable<MVC.Models.TerritoryModels>
@{
ViewBag.Title = "Index";
ViewBag.Title = "All Terriotries";
}
<h2>Index</h2>
<h2>@ViewBag.Title</h2>
<p>
@Html.ActionLink("Create New", "Create")
......
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