Commit 03b69597 authored by Clément's avatar Clément
Browse files

Few Details

parent 3b02b0fe
......@@ -17,19 +17,21 @@ namespace EntitiesLayer
{
public TerritoryType Type { get; set; }
public House Owner { get; set; }
public Territory(TerritoryType type, House owner)
public string Name { get; set; }
public Territory(TerritoryType type, House owner, string name)
{
ID = 0;
Type = type;
Owner = owner;
Name = name;
}
public Territory(int id, TerritoryType type, House owner)
public Territory(int id, TerritoryType type, House owner,string name)
{
ID = id;
Type = type;
Owner = owner;
Name = name;
}
}
}
......@@ -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,63 +42,183 @@ namespace MVC.Controllers
}
// GET: Territory/Create
public ActionResult Create()
public async Task<ActionResult> Create()
{
return View();
TerritoryModels house = new TerritoryModels();
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<TerritoryType> terr = new List<TerritoryType>();
terr.Add(TerritoryType.DESERT);
terr.Add(TerritoryType.LAND);
terr.Add(TerritoryType.MOUNTAIN);
terr.Add(TerritoryType.SEA);
ViewBag.ListType = terr;
return View(house);
}
// POST: Territory/Create
[HttpPost]
public ActionResult Create(FormCollection collection)
// POST: House/Edit/5
public async Task<ActionResult> Create(TerritoryModels collection)
{
try
{
// TODO: Add insert logic here
return RedirectToAction("Index");
TerritoryModels house = new TerritoryModels();
house.Name = collection.Name;
house.Type = collection.Type;
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.Owner.ID);
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
house.Owner = JsonConvert.DeserializeObject<HouseModels>(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 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/Territory", content);
return RedirectToAction("Index");
}
}
// GET: Territory/Edit/5
public ActionResult Edit(int id)
public async Task<ActionResult> Edit(int id)
{
return View();
TerritoryModels house = new 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/" + id);
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
house = JsonConvert.DeserializeObject<TerritoryModels>(temp);
}
}
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<TerritoryType> terr = new List<TerritoryType>();
terr.Add(TerritoryType.DESERT);
terr.Add(TerritoryType.LAND);
terr.Add(TerritoryType.MOUNTAIN);
terr.Add(TerritoryType.SEA);
ViewBag.ListType = terr;
return View(house);
}
// POST: Territory/Edit/5
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
// POST: House/Edit/5
public async Task<ActionResult> Edit(int id, TerritoryModels collection)
{
try
{
// TODO: Add update logic here
return RedirectToAction("Index");
TerritoryModels house = new TerritoryModels();
house.ID = id;
house.Name = collection.Name;
house.Type = collection.Type;
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.Owner.ID);
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
house.Owner = JsonConvert.DeserializeObject<HouseModels>(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 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/Territory", content);
return RedirectToAction("Index");
}
}
// GET: Territory/Delete/5
public ActionResult Delete(int id)
public async Task<ActionResult> Delete(int id)
{
return View();
TerritoryModels character = new 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/" + id);
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
character = JsonConvert.DeserializeObject<TerritoryModels>(temp);
}
}
return View(character);
}
// POST: Territory/Delete/5
// 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/Territory/" + id);
}
return RedirectToAction("Index");
}
catch
......
......@@ -298,6 +298,9 @@
<Content Include="Views\Fight\Edit.cshtml" />
<Content Include="Views\Fight\Create.cshtml" />
<Content Include="Views\War\Details.cshtml" />
<Content Include="Views\Territory\Edit.cshtml" />
<Content Include="Views\Territory\Create.cshtml" />
<Content Include="Views\Territory\Delete.cshtml" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
......
......@@ -14,7 +14,16 @@ namespace MVC.Models
}
public class TerritoryModels
{
public int ID { get; set; }
public TerritoryType Type { get; set; }
public HouseModels Owner { get; set; }
public string Name { get; set; }
public TerritoryModels()
{
ID = 0;
Type = 0;
Owner = null;
Name = "";
}
}
}
\ No newline at end of file
@model MVC.Models.TerritoryModels
@{
ViewBag.Title = "Edit";
}
@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 { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Type, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EnumDropDownListFor(model => model.Type, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Owner, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.Owner.ID, ViewBag.ListHouses as IEnumerable<SelectListItem>, "", new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Owner, "", new { @class = "text-danger" })
@Html.ActionLink("Create new house", "../House/Create")
</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")
}
@model MVC.Models.TerritoryModels
@{
ViewBag.Title = "Delete";
}
<h3>Are you sure you want to delete this?</h3>
<div>
<h4>TerritoryModels</h4>
<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.TerritoryModels
@{
ViewBag.Title = "Edit";
}
@{
ViewBag.Title = "Edit";
}
@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.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">
@Html.LabelFor(model => model.Type, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EnumDropDownListFor(model => model.Type, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Owner, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.Owner.ID, ViewBag.ListHouses as IEnumerable<SelectListItem>, "", new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Owner, "", new { @class = "text-danger" })
@Html.ActionLink("Create new house", "../House/Create")
</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")
}
@model IEnumerable<MVC.Models.TerritoryModels>
@{
ViewBag.Title = "All Territories";
ViewBag.Title = "Index";
}
<h2>@ViewBag.Title</h2>
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
......@@ -12,25 +12,31 @@
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Owner)
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Type)
</th>
<th>
@Html.DisplayNameFor(model => model.Owner)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Owner.Name)
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Type)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
@Html.DisplayFor(modelItem => item.Owner.Name)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.ID })
</td>
</tr>
}
......
......@@ -6,13 +6,14 @@ using BusinessLayer;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using EntitiesLayer;
namespace WebApiGOT.Controllers
{
public class TerritoryController : ApiController
{
// GET: api/Territory
public List<TerritoryDTO> GetAllHouse()
public List<TerritoryDTO> GetAllTerritory()
{
List<TerritoryDTO> list = new List<TerritoryDTO>();
BusinessLayer.ThronesTournamentManager busi = new BusinessLayer.ThronesTournamentManager();
......@@ -33,18 +34,29 @@ namespace WebApiGOT.Controllers
}
// POST: api/Territory
public void Post([FromBody]string value)
public void Post(TerritoryDTO terr)
{
House h = new House(terr.Owner.ID,terr.Owner.Name,terr.Owner.NbUnits);
Territory Terry = new Territory(terr.Type,h,terr.Name);
BusinessLayer.ThronesTournamentManager busi = new BusinessLayer.ThronesTournamentManager();
busi.addTerritory(Terry);
}
// PUT: api/Territory/5
public void Put(int id, [FromBody]string value)
public void Put(TerritoryDTO terr)
{
BusinessLayer.ThronesTournamentManager busi = new BusinessLayer.ThronesTournamentManager();
House h = new House(terr.Owner.ID, terr.Owner.Name, terr.Owner.NbUnits);
Territory Terry = new Territory(terr.ID, terr.Type, h, terr.Name);
busi.updateTerritory(Terry);
}
// DELETE: api/Territory/5
public void Delete(int id)
{
BusinessLayer.ThronesTournamentManager busi = new BusinessLayer.ThronesTournamentManager();
busi.deleteTerritory(id);
}
}
}
......@@ -8,13 +8,24 @@ namespace WebApiGOT.Models
{
public class TerritoryDTO
{
public int ID { get; set; }
public TerritoryType Type { get; set; }
public HouseDTO Owner { get; set; }
public string Name { get; set; }
public TerritoryDTO(Territory t)
{
ID = t.ID;
Type = t.Type;
Owner = new HouseDTO(t.Owner);
Name = t.Name;
}
public TerritoryDTO()
{
ID = 0;
Type = 0;
Owner = null;
Name = "";
}
}
}
\ No newline at end of file
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