Commit 7dc797d8 authored by julescournut's avatar julescournut
Browse files

Jsais pas il est 4h

parent 7f2f6afe
......@@ -337,13 +337,14 @@ namespace DataAccessLayer
DataTable dataTable = SelectByDataAdapter(request);
if (dataTable.Rows.Count == 1)
{
dataTable.Rows[0]["FirstName"] = character.FirstName;
dataTable.Rows[0]["LastName"] = character.LastName;
dataTable.Rows[0]["PV"] = character.Characteristics.PV;
dataTable.Rows[0]["Type"] = (int)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;
DataRow row = dataTable.Rows[0];
row["FirstName"] = character.FirstName;
row["LastName"] = character.LastName;
row["PV"] = character.Characteristics.PV;
row["Type"] = (int)character.Characteristics.Type;
row["Bravoury"] = character.Characteristics.Bravoury;
row["Crazyness"] = character.Characteristics.Crazyness;
row["id_house"] = character.House.ID;
UpdateByCommandBuilder(request, dataTable);
}
}
......
No preview for this file type
No preview for this file type
......@@ -14,9 +14,25 @@ namespace EntitiesLayer
public House Winner { get; set; }
public War War { get; set; }
public Fight(String name, House challenger1, House challenger2, House winner, War war)
public Fight(String name, House challenger1, House challenger2, War war)
{
ID = 0;
Name = name;
Challenger1 = challenger1;
Challenger2 = challenger2;
if(challenger1.NbUnits > challenger2.NbUnits)
{
Winner = challenger1;
}
else
{
Winner = challenger2;
}
War = war;
}
public Fight(String name, House challenger1, House challenger2, House winner, War war)
{
Name = name;
Challenger1 = challenger1;
Challenger2 = challenger2;
......
......@@ -107,7 +107,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/house/" + collection.ID);
HttpResponseMessage response = await client.GetAsync("api/house/" + collection.House.ID);
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
......@@ -163,18 +163,6 @@ namespace MVC.Controllers
}
}
/*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/character/" + character.RelationShips[0].CharacterID);
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
relationships.Concat(new[] { JsonConvert.DeserializeObject<CharacterModels>(temp) });
}
}*/
ViewBag.ListHouses = houses.Select(h => new SelectListItem()
{
Text = h.Name,
......@@ -188,8 +176,13 @@ namespace MVC.Controllers
public async Task<ActionResult> Edit(int id, CharacterModels collection)
{
CharacterModels perso = new CharacterModels();
perso.ID = collection.ID;
perso.FirstName = collection.FirstName;
perso.LastName = collection.LastName;
perso.Characteristics.PV = collection.Characteristics.PV;
perso.Characteristics.Bravoury = collection.Characteristics.Bravoury;
perso.Characteristics.Crazyness = collection.Characteristics.Crazyness;
perso.Characteristics.Type = collection.Characteristics.Type;
using (var client = new HttpClient())
{
......@@ -197,7 +190,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/house/" + collection.ID);
HttpResponseMessage response = await client.GetAsync("api/house/" + collection.House.ID);
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
......@@ -205,9 +198,6 @@ namespace MVC.Controllers
}
}
perso.Characteristics.PV = collection.Characteristics.PV;
perso.Characteristics.Bravoury = collection.Characteristics.Bravoury;
perso.Characteristics.Crazyness = collection.Characteristics.Crazyness;
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:13666/");
......@@ -216,15 +206,29 @@ namespace MVC.Controllers
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
String jsonString = JsonConvert.SerializeObject(perso);
StringContent content = new StringContent(jsonString, System.Text.Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync("api/character", content);
HttpResponseMessage response = await client.PutAsync("api/character", content);
}
return RedirectToAction("Index");
}
// GET: Character/Delete/5
public ActionResult Delete(int id)
public async Task<ActionResult> Delete(int id)
{
return View();
CharacterModels character = new CharacterModels();
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/character/" + id);
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
character = JsonConvert.DeserializeObject<CharacterModels>(temp);
}
}
return View(character);
}
// POST: Fight/Delete/2
......
......@@ -9,6 +9,7 @@ using MVC.Models;
using System.Net.Http;
using Newtonsoft.Json;
using System.Threading.Tasks;
using System.Net.Http.Headers;
namespace MVC.Controllers
{
......@@ -41,25 +42,106 @@ namespace MVC.Controllers
}
// GET: Fght/Create
public ActionResult Create()
public async Task<ActionResult> Create()
{
List<HouseModels> houses = new List<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");
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
houses = JsonConvert.DeserializeObject<List<HouseModels>>(temp);
}
}
ViewBag.ListHouses = houses.Select(h => new SelectListItem()
{
Text = h.Name,
Value = h.ID.ToString()
});
List<WarModels> wars = new List<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");
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
wars = JsonConvert.DeserializeObject<List<WarModels>>(temp);
}
}
ViewBag.ListWar = wars.Select(w => new SelectListItem()
{
Text = w.Name,
Value = w.ID.ToString()
});
return View();
}
// POST: Fights/Create
[HttpPost]
public ActionResult Create(FormCollection collection)
public async Task<ActionResult> Create(FightModels collection)
{
try
FightModels fight = new FightModels();
fight.Name = collection.Name;
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/house/" + collection.Challenger1.ID);
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
fight.Challenger1 = JsonConvert.DeserializeObject<HouseModels>(temp);
}
}
using (var client = new HttpClient())
{
// TODO: Add insert logic here
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/house/" + collection.Challenger2.ID);
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
fight.Challenger2 = JsonConvert.DeserializeObject<HouseModels>(temp);
}
}
return RedirectToAction("Index");
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/war/" + collection.War.ID);
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
fight.War = JsonConvert.DeserializeObject<WarModels>(temp);
}
}
catch
using (var client = new HttpClient())
{
return View();
client.BaseAddress = new Uri("http://localhost:13666/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
String jsonString = JsonConvert.SerializeObject(fight);
StringContent content = new StringContent(jsonString, System.Text.Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync("api/fight", content);
}
return RedirectToAction("Index");
}
// GET: Fight/Edit/1
......@@ -85,9 +167,24 @@ namespace MVC.Controllers
}
// GET: Fight/Delete/1
public ActionResult Delete(int id)
public async Task<ActionResult> Delete(int id)
{
return View();
FightModels fight = new FightModels();
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/fight/" + id);
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
fight = JsonConvert.DeserializeObject<FightModels>(temp);
}
}
return View(fight);
}
// POST: Fight/Delete/2
......
......@@ -9,6 +9,7 @@ using MVC.Models;
using System.Net.Http;
using Newtonsoft.Json;
using System.Threading.Tasks;
using System.Net.Http.Headers;
namespace MVC.Controllers
{
......@@ -22,8 +23,7 @@ namespace MVC.Controllers
{
client.BaseAddress = new Uri("http://localhost:13666/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync("api/House");
if (response.IsSuccessStatusCode)
{
......@@ -55,8 +55,7 @@ namespace MVC.Controllers
{
client.BaseAddress = new Uri("http://localhost:13666/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
String jsonString = JsonConvert.SerializeObject(house);
StringContent content = new StringContent(jsonString, System.Text.Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync("api/House", content);
......@@ -74,9 +73,22 @@ namespace MVC.Controllers
}
public ActionResult Edit(int id)
public async Task<ActionResult> Edit(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);
}
[HttpPost]
......@@ -92,8 +104,7 @@ namespace MVC.Controllers
{
client.BaseAddress = new Uri("http://localhost:13666/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
String jsonString = JsonConvert.SerializeObject(house);
StringContent content = new StringContent(jsonString, System.Text.Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PutAsync("api/house", content);
......@@ -117,8 +128,7 @@ namespace MVC.Controllers
{
client.BaseAddress = new Uri("http://localhost:13666/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.DeleteAsync("api/house/" + id);
}
return RedirectToAction("Index");
......
......@@ -9,7 +9,7 @@ using MVC.Models;
using System.Net.Http;
using Newtonsoft.Json;
using System.Threading.Tasks;
using System.Net.Http.Headers;
namespace MVC.Controllers
{
......@@ -36,9 +36,24 @@ namespace MVC.Controllers
}
// GET: War/Details/0
public ActionResult Details(int id)
public async Task<ActionResult> Details(int id)
{
return View();
IEnumerable<FightModels> fights = new List<FightModels>();
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/Fight");
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
fights = JsonConvert.DeserializeObject<List<FightModels>>(temp);
}
}
ViewBag.Title = (fights.Count() == 0) ? "No Fights for this War" : "All Fights for " + fights.First().War.Name;
return View(fights);
}
// GET: War/Create
......@@ -74,9 +89,22 @@ namespace MVC.Controllers
}
// GET: War/Edit/1
public ActionResult Edit(int id)
public async Task<ActionResult> Edit(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);
}
[HttpPost]
......
......@@ -295,6 +295,9 @@
<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" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
......
......@@ -13,14 +13,15 @@ namespace MVC.Models
public HouseModels Challenger2 { get; set; }
public HouseModels Winner { get; set; }
public WarModels War { get; set; }
public FightModels()
{
ID = 0;
Name = "";
Challenger1 = null;
Challenger2 = null;
Winner = null;
War = null;
Challenger1 = new HouseModels();
Challenger2 = new HouseModels();
Winner = new HouseModels();
War = new WarModels();
}
}
}
\ No newline at end of file
......@@ -34,6 +34,7 @@
<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">
......
......@@ -4,7 +4,7 @@
ViewBag.Title = "Delete";
}
<h3>Are you sure you want to delete this character ?</h3>
<h3>Are you sure you want to delete @Model.FirstName @Model.LastName ?</h3>
<div>
<hr />
......
......@@ -4,7 +4,7 @@
ViewBag.Title = "Edit";
}
<h2>Edit</h2>
<h2>@ViewBag.Title @Model.FirstName @Model.LastName</h2>
@using (Html.BeginForm())
......@@ -35,6 +35,7 @@
<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>
......
......@@ -53,8 +53,8 @@
}
</td> -->
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
@Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
</td>
</tr>
......
@model MVC.Models.FightModels
@{
ViewBag.Title = "Create";
}
<h2>Create</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.Name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBoxFor(model => model.Name, new { @type = "text", @class = "form-control" })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Challenger1, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.Challenger1.ID, ViewBag.ListHouses as IEnumerable<SelectListItem>, "", new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Challenger1, "", new { @class = "text-danger" })
@Html.ActionLink("Create new house", "../House/Create")
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Challenger2, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.Challenger2.ID, ViewBag.ListHouses as IEnumerable<SelectListItem>, "", new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Challenger2, "", new { @class = "text-danger" })
@Html.ActionLink("Create new house", "../House/Create")
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.War, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.War.ID, ViewBag.ListWar as IEnumerable<SelectListItem>, "", new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.War, "", new { @class = "text-danger" })
@Html.ActionLink("Create new war", "../War/Create")
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
@model WebApiGOT.Models.FightDTO
@model MVC.Models.FightModels
@{
ViewBag.Title = "Delete";
}
<h2>Delete</h2>
<h3>Are you sure you want to delete this?</h3>
<h3>Are you sure you want to delete @Model.Name ?</h3>
<div>
<h4>FightDTO</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.Name)
</dt>
<dd>
@Html.DisplayFor(model => model.Name)
</dd>
</dl>
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
<div class="form-actions no-color">
<input type="submit" value="Delete" class="btn btn-default" /> |