Compare commits
1 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
27abe7a5e6 |
|
|
@ -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: /<APIController>
|
||||
[HttpGet]
|
||||
public IEnumerable<String> Get()
|
||||
{
|
||||
List<String> 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 /<APIController>/5
|
||||
[HttpGet("{id}")]
|
||||
public string Get(int id)
|
||||
{
|
||||
return "value";
|
||||
}
|
||||
|
||||
// POST /<APIController>
|
||||
[HttpPost]
|
||||
public void Post([FromBody] string value)
|
||||
{
|
||||
}
|
||||
|
||||
// PUT /<APIController>/5
|
||||
[HttpPut("{id}")]
|
||||
public void Put(int id, [FromBody] string value)
|
||||
{
|
||||
}
|
||||
|
||||
// DELETE /<APIController>/5
|
||||
[HttpDelete("{id}")]
|
||||
public void Delete(int id)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<AssaultTroop> ObjectAssaultTroopList = _db.AssaultTroops.ToList();
|
||||
// If the above line faulters then ensure SQL Server is running
|
||||
return View(ObjectAssaultTroopList);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IEnumerable<String> Get()
|
||||
{
|
||||
List<String> 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 /<APIController>/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 /<APIController>
|
||||
[HttpPost]
|
||||
public void Post([FromBody] string value)
|
||||
{
|
||||
// TODO: Implement
|
||||
}
|
||||
|
||||
// PUT /<APIController>/5
|
||||
[HttpPut("{id}")]
|
||||
public void Put(int id, [FromBody] string value)
|
||||
{
|
||||
// TODO: Implement
|
||||
}
|
||||
|
||||
// DELETE /<APIController>/5
|
||||
[HttpDelete("{id}")]
|
||||
public void Delete(int id)
|
||||
{
|
||||
// TODO: Implement
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -18,5 +18,47 @@ namespace BHServer.Controllers
|
|||
// If the above line faulters then ensure SQL Server is running
|
||||
return View(ObjectProvinceList);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IEnumerable<String> Get()
|
||||
{
|
||||
List<String> 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 /<APIController>/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 /<APIController>
|
||||
[HttpPost]
|
||||
public void Post([FromBody] string value)
|
||||
{
|
||||
// TODO: Implement
|
||||
}
|
||||
|
||||
// PUT /<APIController>/5
|
||||
[HttpPut("{id}")]
|
||||
public void Put(int id, [FromBody] string value)
|
||||
{
|
||||
// TODO: Implement
|
||||
}
|
||||
|
||||
// DELETE /<APIController>/5
|
||||
[HttpDelete("{id}")]
|
||||
public void Delete(int id)
|
||||
{
|
||||
// TODO: Implement
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,5 +14,7 @@ namespace BHServer.Data
|
|||
// to run migrations, run `add-migration <name of the migration>` in the NuGet console
|
||||
// then make the migrations from the console by using `update-database`
|
||||
// to rollback migrations run the command `remove-migration <name>`
|
||||
|
||||
public DbSet<AssaultTroop> AssaultTroops { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue