Commit 2b5c62a0 authored by Clément's avatar Clément
Browse files

Création character

parent bc71118b
......@@ -48,30 +48,55 @@ namespace MVC.Controllers
// POST: Character/Create
[HttpPost]
/* public ActionResult Create(CharacterModels collection)
{
try
{
CharacterModels perso = new CharacterModels();
perso._id = collection._id;
perso._firstName = collection._firstName;
perso._lastName = collection._lastName;
perso._pv = collection._pv;
perso._bravoury = collection._bravoury;
perso._crazyness = collection._crazyness;
public async Task<ActionResult> Create(CharacterModels collection)
{
try
{
IEnumerable<CharacterModels> Characters = new List<CharacterModels>();
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/character");
if (response.IsSuccessStatusCode)
{
string temp = await response.Content.ReadAsStringAsync();
Characters = JsonConvert.DeserializeObject<List<CharacterModels>>(temp);
}
}
ViewBag.listHouse = Characters;
CharacterModels perso = new CharacterModels();
//perso._id = collection._id;
perso.House=collection.House;
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;
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(perso);
StringContent content = new StringContent(jsonString, System.Text.Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync("api/character", content);
return View();
}
}
using (var client = new WebClient())
var response = client.UploadValues("", perso);
var responseString = Enc
catch
{
return View();
return RedirectToAction("Index");
}
catch
{
return View();
}
}*/
}
}
// GET: Character/Edit/5
public ActionResult Edit(int id)
{
......
......@@ -23,13 +23,39 @@ namespace MVC.Models
LEADER,
LOSER
}
public class Characteristics
{
public uint PV { get; set; }
public CharacterType Type { get; set; }
public int Bravoury { get; set; }
public int Crazyness { get; set; }
public Characteristics(uint pv, CharacterType type, int bravoury, int crazyness)
{
PV = pv;
Type = type;
Bravoury = bravoury;
Crazyness = crazyness;
}
}
public class CharacterModels
{
public string _firstName { get; set; }
public string _lastName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public HouseModels House { get; set; }
public Characteristics Characteristics { get; set; }
public Dictionary<CharacterModels, RelationshipType> RelationShips { get; set; }
public CharacterModels()
{
FirstName = "";
LastName = "";
House = null;
Characteristics = null;
RelationShips = null;
}
}
}
\ No newline at end of file
......@@ -16,51 +16,22 @@
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model._id, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.LabelFor(model => model.FirstName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model._id, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model._id, "", new { @class = "text-danger" })
@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._firstName, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.LabelFor(model => model.LastName, 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" })
@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._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._pv, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model._pv, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model._pv, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model._bravoury, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model._bravoury, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model._bravoury, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model._crazyness, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model._crazyness, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model._crazyness, "", new { @class = "text-danger" })
</div>
<div>
@Html.DropDownList("Maison", ViewBag.listHouse as IEnumerable<House>)
</div>
<div class="form-group">
......
......@@ -23,5 +23,12 @@ namespace WebApiGOT.Controllers
return list;
}
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,c.House);
BusinessLayer.ThronesTournamentManager busi = new BusinessLayer.ThronesTournamentManager();
busi.addCharacter(cha);
}
}
}
......@@ -14,15 +14,6 @@ namespace WebApiGOT.Models
RIVALRY
}
public enum CharacterType
{
WARRIOR,
WITCH,
TACTITIAN,
LEADER,
LOSER
}
public class Characteristics
{
public uint PV { get; set; }
......@@ -43,6 +34,14 @@ namespace WebApiGOT.Models
public string FirstName { get; set; }
public string LastName { get; set; }
public House House { get; set; }
public Characteristics Characteristics { get; set; }
public Dictionary<CharacterDTO, RelationshipType> RelationShips { get; set; }
public CharacterDTO()
{
FirstName = "";
LastName = "";
House =null;
}
public CharacterDTO(Character c)
{
......@@ -51,5 +50,11 @@ namespace WebApiGOT.Models
LastName = c.LastName;
House = c.House;
}
}
public CharacterDTO(String firstName, String lastName)
{
FirstName = firstName;
LastName = lastName;
}
}
}
\ 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