diff --git a/Controllers/APIController.cs b/Controllers/APIController.cs deleted file mode 100644 index 22f91ed..0000000 --- a/Controllers/APIController.cs +++ /dev/null @@ -1,56 +0,0 @@ -using BHServer.Data; -using Microsoft.AspNetCore.Mvc; - -// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 - -namespace BHServer.Controllers -{ - [Route("[controller]")] - [ApiController] - public class APIController : ControllerBase - { - private readonly ApplicationDbContext _db; - public APIController(ApplicationDbContext db) - { - _db = db; - } - - // GET: / - [HttpGet] - public IEnumerable Get() - { - List arr = []; - foreach (var entry in _db.Provinces.ToList()) - { - String str = @"{""id"": " + entry.ProvinceId + @", ""name"": """ + entry.Name + @""", ""faction"": " + entry.Faction + @", ""mul"": " + entry.Multiplier + @", ""ats"": " + entry.ATs + @", ""state"": " + entry.State + "}"; - arr.Add(str); - } - return arr; - } - - // GET //5 - [HttpGet("{id}")] - public string Get(int id) - { - return "value"; - } - - // POST / - [HttpPost] - public void Post([FromBody] string value) - { - } - - // PUT //5 - [HttpPut("{id}")] - public void Put(int id, [FromBody] string value) - { - } - - // DELETE //5 - [HttpDelete("{id}")] - public void Delete(int id) - { - } - } -} diff --git a/Controllers/AssaultTroopController.cs b/Controllers/AssaultTroopController.cs new file mode 100644 index 0000000..6fe0789 --- /dev/null +++ b/Controllers/AssaultTroopController.cs @@ -0,0 +1,64 @@ +using BHServer.Data; +using BHServer.Models; +using Microsoft.AspNetCore.Mvc; +using System; + +namespace BHServer.Controllers +{ + public class AssaultTroopController : Controller + { + private readonly ApplicationDbContext _db; + public AssaultTroopController(ApplicationDbContext db) + { + _db = db; + } + public IActionResult Index() + { + List ObjectAssaultTroopList = _db.AssaultTroops.ToList(); + // If the above line faulters then ensure SQL Server is running + return View(ObjectAssaultTroopList); + } + + [HttpGet] + public IEnumerable Get() + { + List arr = []; + foreach (var entry in _db.AssaultTroops.ToList()) + { + String str = @"{""id"": " + entry.Id + @", ""name"": """ + entry.Name + @""", ""faction"": " + entry.Faction + @", ""type"": " + entry.Type + @", ""province"": " + entry.Province + @", ""orders"": " + entry.Orders + @", ""owner"": " + entry.Owner + "}"; + arr.Add(str); + } + return arr; + } + + // GET //5 + [HttpGet("{id}")] + public String Get(int id) + { + var entry = _db.AssaultTroops.ElementAt(id); + String str = @"{""id"": " + entry.Id + @", ""name"": """ + entry.Name + @""", ""faction"": " + entry.Faction + @", ""type"": " + entry.Type + @", ""province"": " + entry.Province + @", ""orders"": " + entry.Orders + @", ""owner"": " + entry.Owner + "}"; + return str; + } + + // POST / + [HttpPost] + public void Post([FromBody] string value) + { + // TODO: Implement + } + + // PUT //5 + [HttpPut("{id}")] + public void Put(int id, [FromBody] string value) + { + // TODO: Implement + } + + // DELETE //5 + [HttpDelete("{id}")] + public void Delete(int id) + { + // TODO: Implement + } + } +} diff --git a/Controllers/ProvinceController.cs b/Controllers/ProvinceController.cs index 8713900..6452479 100644 --- a/Controllers/ProvinceController.cs +++ b/Controllers/ProvinceController.cs @@ -18,5 +18,47 @@ namespace BHServer.Controllers // If the above line faulters then ensure SQL Server is running return View(ObjectProvinceList); } + + [HttpGet] + public IEnumerable Get() + { + List arr = []; + foreach (var entry in _db.Provinces.ToList()) + { + String str = @"{""id"": " + entry.ProvinceId + @", ""name"": """ + entry.Name + @""", ""faction"": " + entry.Faction + @", ""mul"": " + entry.Multiplier + @", ""ats"": " + entry.ATs + @", ""state"": " + entry.State + "}"; + arr.Add(str); + } + return arr; + } + + // GET //5 + [HttpGet("{id}")] + public String Get(int id) + { + var entry = _db.Provinces.ElementAt(id); + String str = @"{""id"": " + entry.ProvinceId + @", ""name"": """ + entry.Name + @""", ""faction"": " + entry.Faction + @", ""mul"": " + entry.Multiplier + @", ""ats"": " + entry.ATs + @", ""state"": " + entry.State + "}"; + return str; + } + + // POST / + [HttpPost] + public void Post([FromBody] string value) + { + // TODO: Implement + } + + // PUT //5 + [HttpPut("{id}")] + public void Put(int id, [FromBody] string value) + { + // TODO: Implement + } + + // DELETE //5 + [HttpDelete("{id}")] + public void Delete(int id) + { + // TODO: Implement + } } } diff --git a/Data/ApplicationDbContext.cs b/Data/ApplicationDbContext.cs index cb4f444..9f627f1 100644 --- a/Data/ApplicationDbContext.cs +++ b/Data/ApplicationDbContext.cs @@ -14,5 +14,7 @@ namespace BHServer.Data // to run migrations, run `add-migration ` in the NuGet console // then make the migrations from the console by using `update-database` // to rollback migrations run the command `remove-migration ` + + public DbSet AssaultTroops { get; set; } } } diff --git a/Models/AssaultTroopModel.cs b/Models/AssaultTroopModel.cs new file mode 100644 index 0000000..6be54cc --- /dev/null +++ b/Models/AssaultTroopModel.cs @@ -0,0 +1,23 @@ +using System.ComponentModel.DataAnnotations; + +namespace BHServer.Models +{ + public class AssaultTroop + { + [Key] + public int Id { get; set; } + public int ATId { get; set; } + [Required] + public string Name { get; set; } + [Required] + public int Faction { get; set; } // 0 - Neutral, 1 - Allies, 2 - Axis + [Required] + public int Type { get; set; } // 1 - infantry, 4 - Armor + [Required] + public int Province { get; set; } // -1 - not deployed, provinces id + [Required] + public string Orders { get; set; } // Json String + [Required] + public int Owner { get; set; } // owner id + } +}