Commit 6a9bb46c authored by Clément's avatar Clément
Browse files

Few Details

parent 6a39a4cb
......@@ -10,6 +10,7 @@ using System.Net.Http;
using Newtonsoft.Json;
using System.Threading.Tasks;
namespace MVC.Controllers
{
public class WarController : Controller
......@@ -48,13 +49,23 @@ namespace MVC.Controllers
// POST: War/Create
[HttpPost]
public ActionResult Create(FormCollection collection)
public async Task<ActionResult> Create(WarModels collection)
{
try
{
// TODO: Add insert logic here
return RedirectToAction("Index");
WarModels house = new WarModels();
house.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"));
String jsonString = JsonConvert.SerializeObject(house);
StringContent content = new StringContent(jsonString, System.Text.Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync("api/war", content);
}
return RedirectToAction("Index");
}
catch
{
......@@ -68,19 +79,24 @@ namespace MVC.Controllers
return View();
}
// POST: War/Edit/1
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
// POST: House/Edit/5
public async Task<ActionResult> Edit(int id, WarModels collection)
{
try
{
// TODO: Add update logic here
return RedirectToAction("Index");
}
catch
WarModels war = new WarModels();
war.ID = id;
war.Name = collection.Name;
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(war);
StringContent content = new StringContent(jsonString, System.Text.Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PutAsync("api/war", content);
return RedirectToAction("Index");
}
}
......@@ -90,14 +106,21 @@ namespace MVC.Controllers
return View();
}
// POST: War/Delete/1
// POST: Fight/Delete/2
[HttpPost]
public ActionResult Delete(int id, FormCollection collection)
public async Task<ActionResult> Delete(int id, FormCollection collection)
{
try
{
// TODO: Add delete logic here
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.DeleteAsync("api/war/" + id);
}
return RedirectToAction("Index");
}
catch
......
......@@ -290,6 +290,9 @@
<Content Include="Views\House\Create.cshtml" />
<Content Include="Views\House\Edit.cshtml" />
<Content Include="Views\House\Delete.cshtml" />
<Content Include="Views\War\Create.cshtml" />
<Content Include="Views\War\Delete.cshtml" />
<Content Include="Views\War\Edit.cshtml" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
......
......@@ -7,6 +7,12 @@ namespace MVC.Models
{
public class WarModels
{
public int ID;
public String Name { get; set; }
public WarModels()
{
ID = 0;
Name = "";
}
}
}
\ No newline at end of file
@model MVC.Models.WarModels
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>WarModels</h4>
<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.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
</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 MVC.Models.WarModels
@{
ViewBag.Title = "Delete";
}
<h3>Are you sure you want to delete this war?</h3>
<div>
<hr />
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
<div class="form-actions no-color">
<input type="submit" value="Delete" class="btn btn-default" />
<br><br>
@Html.ActionLink("Back to List", "Index")
</div>
}
</div>
@model MVC.Models.WarModels
@{
ViewBag.Title = "Edit";
}
<h2>Edit</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>WarModels</h4>
<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.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Name, "", 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")
}
......@@ -23,9 +23,8 @@
@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 */ })
@Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
@Html.ActionLink("Delete", "Delete", new {id=item.ID })
</td>
</tr>
}
......
......@@ -6,6 +6,8 @@ using BusinessLayer;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using EntitiesLayer;
namespace WebApiGOT.Controllers
{
......@@ -25,7 +27,7 @@ namespace WebApiGOT.Controllers
}
// GET: api/War/2
public WarDTO Get(int id)
public WarDTO GetWar(int id)
{
BusinessLayer.ThronesTournamentManager busi = new BusinessLayer.ThronesTournamentManager();
......@@ -33,18 +35,26 @@ namespace WebApiGOT.Controllers
}
// POST: api/War
public void Post([FromBody]string value)
public void PostAddWar(WarDTO war)
{
War wa = new War(war.Name);
BusinessLayer.ThronesTournamentManager busi = new BusinessLayer.ThronesTournamentManager();
busi.addWar(wa);
}
// PUT: api/War/2
public void Put(int id, [FromBody]string value)
public void PutEditWar(WarDTO war)
{
War wa = new War(war.ID, war.Name);
BusinessLayer.ThronesTournamentManager busi = new BusinessLayer.ThronesTournamentManager();
busi.updateWar(wa);
}
// DELETE: api/War/2
public void Delete(int id)
{
BusinessLayer.ThronesTournamentManager busi = new BusinessLayer.ThronesTournamentManager();
busi.deleteWar(id);
}
}
}
......@@ -8,10 +8,16 @@ namespace WebApiGOT.Models
{
public class WarDTO
{
public int ID;
public String Name { get; set; }
public WarDTO()
{
ID = 0;
Name = "";
}
public WarDTO(War w)
{
ID = w.ID;
Name = w.Name;
}
}
......
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