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

drop down list of house

parent b95b7074
......@@ -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)
{
......
No preview for this file type
No preview for this file type
......@@ -39,9 +39,17 @@ namespace EntitiesLayer
public House House { get; set; }
public List<RelationShip> RelationShips { get; set; }
public Character(string firstName, string lastName)
{
FirstName = firstName;
LastName = lastName;
Characteristics = new Characteristics(100, 0, 100, 50);
House = new House("Faceless", 0);
RelationShips = new List<RelationShip>();
}
public Character(string firstName, string lastName, uint pv, CharacterType type, int bravoury, int crazyness, House house)
{
ID = 0;
FirstName = firstName;
LastName = lastName;
Characteristics = new Characteristics(pv, type, bravoury, crazyness);
......
......@@ -35,9 +35,38 @@ namespace MVC.Controllers
}
// GET: Character/Details/5
public ActionResult Details(int id)
public async Task<ActionResult> Details(int id)
{
return View();
CharacterModels character = new CharacterModels();
IEnumerable<CharacterModels> relationships = new List<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);
}
}
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);
}
}
return View(character);
}
// GET: Character/Create
......@@ -69,10 +98,23 @@ namespace MVC.Controllers
public async Task<ActionResult> Create(CharacterModels collection)
{
CharacterModels perso = new CharacterModels();
//perso._id = collection._id;
perso.House=collection.House;
perso.FirstName = collection.FirstName;
perso.LastName = collection.LastName;
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.ID);
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
perso.House = JsonConvert.DeserializeObject<HouseModels>(temp);
}
}
perso.Characteristics.PV = collection.Characteristics.PV;
perso.Characteristics.Bravoury = collection.Characteristics.Bravoury;
perso.Characteristics.Crazyness = collection.Characteristics.Crazyness;
......@@ -86,29 +128,97 @@ namespace MVC.Controllers
StringContent content = new StringContent(jsonString, System.Text.Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync("api/character", content);
}
return View();
return RedirectToAction("Index");
}
// GET: Character/Edit/5
public ActionResult Edit(int id)
public async Task<ActionResult> Edit(int id)
{
return View();
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);
}
}
CharacterModels character = new CharacterModels();
IEnumerable<CharacterModels> relationships = new List<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);
}
}
/*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,
Value = h.ID.ToString()
});
return View(character);
}
// POST: Character/Edit/5
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
public async Task<ActionResult> Edit(int id, CharacterModels collection)
{
try
{
// TODO: Add update logic here
CharacterModels perso = new CharacterModels();
perso.FirstName = collection.FirstName;
perso.LastName = collection.LastName;
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/house/" + collection.ID);
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
perso.House = JsonConvert.DeserializeObject<HouseModels>(temp);
}
}
catch
perso.Characteristics.PV = collection.Characteristics.PV;
perso.Characteristics.Bravoury = collection.Characteristics.Bravoury;
perso.Characteristics.Crazyness = collection.Characteristics.Crazyness;
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(perso);
StringContent content = new StringContent(jsonString, System.Text.Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync("api/character", content);
}
return RedirectToAction("Index");
}
// GET: Character/Delete/5
......
......@@ -286,7 +286,6 @@
<Content Include="Views\War\Index.cshtml" />
<Content Include="Views\Territory\Index.cshtml" />
<Content Include="Views\Character\Delete.cshtml" />
<Content Include="Views\Character\Details.cshtml" />
<Content Include="Views\House\Create.cshtml" />
<Content Include="Views\House\Edit.cshtml" />
<Content Include="Views\House\Delete.cshtml" />
......@@ -294,6 +293,8 @@
<Content Include="Views\War\Delete.cshtml" />
<Content Include="Views\War\Edit.cshtml" />
<Content Include="Views\Fight\Delete.cshtml" />
<Content Include="Views\Character\Edit.cshtml" />
<Content Include="Views\Character\Details.cshtml" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
......
......@@ -53,9 +53,9 @@ namespace MVC.Models
ID = 0;
FirstName = "";
LastName = "";
House = null;
Characteristics = null;
RelationShips = null;
House = new HouseModels();
Characteristics = new CharacteristicsModels();
RelationShips = new List<RelationShipModels>();
}
}
}
\ No newline at end of file
......@@ -10,6 +10,7 @@ namespace MVC.Models
public int ID { get; set; }
public string Name { get; set; }
public int NbUnits { get; set; }
public HouseModels()
{
ID = 0;
......
......@@ -15,12 +15,18 @@ namespace MVC.Models
public class RelationShipModels
{
public CharacterModels Character { get; set; }
public int CharacterID { get; set; }
public RelationshipType Type { get; set; }
public RelationShipModels(CharacterModels character, RelationshipType type)
public RelationShipModels()
{
Character = character;
CharacterID = 0;
Type = RelationshipType.FRIENDSHIP;
}
public RelationShipModels(int characterID, RelationshipType type)
{
CharacterID = characterID;
Type = type;
}
}
......
......@@ -4,11 +4,9 @@
ViewBag.Title = "Details";
}
<h2>Details</h2>
<h2>@ViewBag.Title</h2>
<div>
<h4>CharacterModels</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.FirstName)
......@@ -25,10 +23,53 @@
<dd>
@Html.DisplayFor(model => model.LastName)
</dd>
<dt>
@Html.DisplayNameFor(model => model.House)
</dt>
<dd>
@Html.DisplayFor(model => model.House.Name)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Characteristics.Bravoury)
</dt>
<dd>
@Html.DisplayFor(model => model.Characteristics.Bravoury)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Characteristics.Crazyness)
</dt>
<dd>
@Html.DisplayFor(model => model.Characteristics.Crazyness)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Characteristics.PV)
</dt>
<dd>
@Html.DisplayFor(model => model.Characteristics.PV)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Characteristics.Type)
</dt>
<dd>
@Html.DisplayFor(model => model.Characteristics.Type)
</dd>
<dt>
@Html.DisplayNameFor(model => model.RelationShips)
</dt>
@foreach (var rel in Model.RelationShips) {
<dd>
@Html.DisplayFor(model => rel.CharacterID)
</dd>
<dd>
@Html.DisplayFor(model => rel.Type)
</dd>
}
</dl>
</div>
<p>
@Html.ActionLink("Edit", "Edit", new { /* id = Model.PrimaryKey */ }) |
<br>
@Html.ActionLink("Edit", "Edit", new { id = Model.ID })
<br>
@Html.ActionLink("Back to List", "Index")
</p>
@model MVC.Models.CharacterModels
@{
ViewBag.Title = "Edit";
}
<h2>Edit</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" })
</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")
}
@model IEnumerable<MVC.Models.CharacterModels>
@{
ViewBag.Title = "All characters";
ViewBag.Title = "All Characters";
}
<h2>@ViewBag.Title</h2>
......@@ -45,7 +45,7 @@
<td>
@foreach (var rel in item.RelationShips) {
<td>
@Html.DisplayFor(modelItem => rel.Character))
@Html.DisplayFor(modelItem => rel.CharacterID))
</td>
<td>
@Html.DisplayFor(modelItem => rel.Type))
......
@model IEnumerable<MVC.Models.HouseModels>
@{
ViewBag.Title = "House list";
ViewBag.Title = "All Houses";
}
<h2>@ViewBag.Title</h2>
......
@model IEnumerable<MVC.Models.TerritoryModels>
@{
ViewBag.Title = "Territory List";
ViewBag.Title = "All Territories";
}
<h2>@ViewBag.Title</h2>
......
@model IEnumerable<MVC.Models.WarModels>
@{
ViewBag.Title = "War List";
ViewBag.Title = "All Wars";
}
<h2>@ViewBag.Title</h2>
......
......@@ -24,12 +24,27 @@ namespace WebApiGOT.Controllers
return list;
}
public CharacterDTO GetCharacter(int id)
{
BusinessLayer.ThronesTournamentManager busi = new BusinessLayer.ThronesTournamentManager();
CharacterDTO carac = new CharacterDTO(busi.getCharacterById(id));
return carac;
}
public void PostAddCharacter(CharacterDTO c)
{
Character cha = new Character(c.FirstName, c.LastName,c.Characteristics.PV,c.Characteristics.Type,c.Characteristics.Bravoury,c.Characteristics.Crazyness,new House(c.House.Name, c.House.NbUnits));
Character cha = new Character(c.FirstName, c.LastName);
BusinessLayer.ThronesTournamentManager busi = new BusinessLayer.ThronesTournamentManager();
busi.addCharacter(cha);
}
public void PutEditCharacter(CharacterDTO carac)
{
Character cha = new Character(carac.FirstName, carac.LastName);
BusinessLayer.ThronesTournamentManager busi = new BusinessLayer.ThronesTournamentManager();
busi.deleteCharacater(carac.ID);
busi.addCharacter(cha);
}
public void DeleteCharacter(int id)
{
BusinessLayer.ThronesTournamentManager busi = new BusinessLayer.ThronesTournamentManager();
......
......@@ -13,12 +13,20 @@ namespace WebApiGOT.Models
public int Bravoury { get; set; }
public int Crazyness { get; set; }
public CharacteristicsDTO()
{
PV = 0;
Type = CharacterType.LEADER;
Bravoury = 0;
Crazyness = 0;
}
public CharacteristicsDTO(Characteristics c)
{
PV = c.PV;
Type = c.Type;
Bravoury = Bravoury;
Crazyness = Crazyness;
Bravoury = c.Bravoury;
Crazyness = c.Crazyness;
}
}
......@@ -31,6 +39,16 @@ namespace WebApiGOT.Models
public CharacteristicsDTO Characteristics { get; set; }
public List<RelationShipDTO> RelationShips { get; set; }
public CharacterDTO()
{
ID = 0;
FirstName = "";
LastName = "";
House = new HouseDTO();
Characteristics = new CharacteristicsDTO();
RelationShips = new List<RelationShipDTO>();
}
public CharacterDTO(Character c)
{
ID = c.ID;
......
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