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 } } }