Compare commits

...
This repository has been archived on 2025-04-28. You can view files and clone it, but cannot push or open issues/pull-requests.

1 Commits
master ... sql

Author SHA1 Message Date
Surya-AI 27abe7a5e6 added the assault troops 2024-11-18 13:18:34 +05:30
5 changed files with 131 additions and 56 deletions

View File

@ -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)
{
}
}
}

View File

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

View File

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

View File

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

View File

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