added a new controller

sql
Surya-AI 2024-11-18 00:49:36 +05:30
parent 8dcf5c40f9
commit f27e8d6c80
2 changed files with 57 additions and 0 deletions

View File

@ -11,6 +11,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
<PrivateAssets>all</PrivateAssets>

View File

@ -0,0 +1,56 @@
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)
{
}
}
}