by rest api (not recommanded)

main
syneffort 12 months ago
parent 4a7924d9e9
commit b4e9717685
  1. 49
      DataTableRemoting/DataTableAPIHost/Controllers/DataTableController.cs
  2. 26
      DataTableRemoting/DataTableAPIHost/DataManager.cs
  3. 14
      DataTableRemoting/DataTableAPIHost/DataTableAPIHost.csproj
  4. 35
      DataTableRemoting/DataTableAPIHost/Program.cs
  5. 31
      DataTableRemoting/DataTableAPIHost/Properties/launchSettings.json
  6. 13
      DataTableRemoting/DataTableAPIHost/WeatherForecast.cs
  7. 8
      DataTableRemoting/DataTableAPIHost/appsettings.Development.json
  8. 9
      DataTableRemoting/DataTableAPIHost/appsettings.json
  9. 9
      DataTableRemoting/DataTableRemoting.sln

@ -0,0 +1,49 @@
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System.Data;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace DataTableAPIHost.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class DataTableController : ControllerBase
{
// GET: api/<DataTableController>
[HttpGet]
public string Get()
{
return JsonConvert.SerializeObject(DataManager.Instance.DataTable);
}
// GET api/<DataTableController>/5
[HttpGet("{id}")]
public string Get(int id)
{
DataRow[] rows = DataManager.Instance.DataTable.Select($"ID = {id}");
return JsonConvert.SerializeObject(rows[0]);
}
//// POST api/<DataTableController>
//[HttpPost]
//public string Post([FromBody] string value)
//{
// return "";
//}
//// PUT api/<DataTableController>/5
//[HttpPut("{id}")]
//public string Put(int id, [FromBody] string value)
//{
// return "";
//}
//// DELETE api/<DataTableController>/5
//[HttpDelete("{id}")]
//public DataTable Delete(int id)
//{
//}
}
}

@ -0,0 +1,26 @@
using System.Data;
namespace DataTableAPIHost
{
public class DataManager
{
public static DataManager Instance = new DataManager();
public DataManager()
{
if (Instance == null)
{
_dataTable = new DataTable("SampleTable");
_dataTable.Columns.Add("ID", typeof(int));
_dataTable.Columns.Add("Name", typeof(string));
_dataTable.Rows.Add(1, "John");
_dataTable.Rows.Add(2, "Ronaldo");
_dataTable.Rows.Add(3, "Messi");
}
}
DataTable _dataTable;
public DataTable DataTable { get { return _dataTable; } }
}
}

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
</Project>

@ -0,0 +1,35 @@
namespace DataTableAPIHost
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
}
}
}

@ -0,0 +1,31 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:53804",
"sslPort": 44380
}
},
"profiles": {
"DataTableAPIHost": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7050;http://localhost:5259",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

@ -0,0 +1,13 @@
namespace DataTableAPIHost
{
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
}

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

@ -11,6 +11,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataTableWCFClient", "DataT
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WCF", "WCF", "{35D8B24C-91B6-47F4-AEBC-1FEF7FCF2866}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WebService", "WebService", "{4F8C407D-03AF-4010-A10D-3228D7810EF5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataTableAPIHost", "DataTableAPIHost\DataTableAPIHost.csproj", "{8598A97E-811F-405C-BCEE-3E9077D503F6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -29,6 +33,10 @@ Global
{2BC29718-BCFE-4069-881A-595AC1688F8A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2BC29718-BCFE-4069-881A-595AC1688F8A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2BC29718-BCFE-4069-881A-595AC1688F8A}.Release|Any CPU.Build.0 = Release|Any CPU
{8598A97E-811F-405C-BCEE-3E9077D503F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8598A97E-811F-405C-BCEE-3E9077D503F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8598A97E-811F-405C-BCEE-3E9077D503F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8598A97E-811F-405C-BCEE-3E9077D503F6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -37,6 +45,7 @@ Global
{07A3D554-0C5E-4A63-A1B1-2D48165701A4} = {35D8B24C-91B6-47F4-AEBC-1FEF7FCF2866}
{6E02E64B-D7C0-4593-8CCF-75D680AEB188} = {35D8B24C-91B6-47F4-AEBC-1FEF7FCF2866}
{2BC29718-BCFE-4069-881A-595AC1688F8A} = {35D8B24C-91B6-47F4-AEBC-1FEF7FCF2866}
{8598A97E-811F-405C-BCEE-3E9077D503F6} = {4F8C407D-03AF-4010-A10D-3228D7810EF5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {659C8570-938B-451A-8E1F-087AA1B1F50D}

Loading…
Cancel
Save