65 lines
1.9 KiB
C#
65 lines
1.9 KiB
C#
using BHServer.Data;
|
|
using BHServer.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
|
|
namespace BHServer.Controllers
|
|
{
|
|
public class ProvinceController : Controller
|
|
{
|
|
private readonly ApplicationDbContext _db;
|
|
public ProvinceController(ApplicationDbContext db)
|
|
{
|
|
_db = db;
|
|
}
|
|
public IActionResult Index()
|
|
{
|
|
List<Province> ObjectProvinceList = _db.Provinces.ToList();
|
|
// 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
|
|
}
|
|
}
|
|
}
|