Skip to content

Commit 8a12d9f

Browse files
Binding data from remote service to angular data grid
* URLAdaptor * WebMethodAdaptor * WebApiAdaptor * GraphQLAdaptor * ODataV4Adaptor * RemoteSaveAdaptor
1 parent 999680e commit 8a12d9f

36 files changed

+985
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using RemoteSaveAdaptor.Server.Models;
3+
4+
namespace RemoteSaveAdaptor.Server.Controllers
5+
{
6+
[ApiController]
7+
public class OrdersController : Controller
8+
{
9+
[HttpPost]
10+
[Route("api/[controller]")]
11+
public object Post()
12+
{
13+
// Retrieve data from the data source (e.g., database)
14+
IQueryable<OrdersDetails> DataSource = GetOrderData().AsQueryable();
15+
16+
// Get the total records count
17+
int totalRecordsCount = DataSource.Count();
18+
19+
// Return data based on the request
20+
return new { result = DataSource, count = totalRecordsCount };
21+
}
22+
23+
[HttpGet]
24+
[Route("api/[controller]")]
25+
public List<OrdersDetails> GetOrderData()
26+
{
27+
var data = OrdersDetails.GetAllRecords().ToList();
28+
return data;
29+
}
30+
31+
[HttpPost]
32+
[Route("api/Orders/Insert")]
33+
public ActionResult Insert([FromBody] CRUDModel<OrdersDetails> newRecord)
34+
{
35+
if (newRecord.value !=null)
36+
{
37+
OrdersDetails.GetAllRecords().Insert(0, newRecord.value);
38+
}
39+
40+
return Json(newRecord.value);
41+
}
42+
43+
[HttpPost]
44+
[Route("api/Orders/Update")]
45+
public object Update([FromBody] CRUDModel<OrdersDetails> updatedRecord)
46+
{
47+
var updatedOrder = updatedRecord.value;
48+
if (updatedOrder != null)
49+
{
50+
var data = OrdersDetails.GetAllRecords().FirstOrDefault(or => or.OrderID == updatedOrder.OrderID);
51+
if (data != null)
52+
{
53+
// Update the existing record
54+
data.OrderID = updatedOrder.OrderID;
55+
data.CustomerID = updatedOrder.CustomerID;
56+
data.Freight = updatedOrder.Freight;
57+
data.ShipCity = updatedOrder.ShipCity;
58+
data.ShipCountry = updatedOrder.ShipCountry;
59+
data.Verified = updatedOrder.Verified;
60+
61+
// Update other properties similarly
62+
}
63+
}
64+
return updatedRecord;
65+
}
66+
67+
[HttpPost]
68+
[Route("api/Orders/Remove")]
69+
public object Remove([FromBody] CRUDModel<OrdersDetails> deletedRecord)
70+
{
71+
int orderId = int.Parse(deletedRecord.key.ToString()); // get key value from the deletedRecord
72+
var data = OrdersDetails.GetAllRecords().FirstOrDefault(orderData => orderData.OrderID == orderId);
73+
if (data != null)
74+
{
75+
// Remove the record from the data collection
76+
OrdersDetails.GetAllRecords().Remove(data);
77+
}
78+
return deletedRecord;
79+
}
80+
81+
public class CRUDModel<T> where T : class
82+
{
83+
public string? action { get; set; }
84+
public string? keyColumn { get; set; }
85+
public object? key { get; set; }
86+
public T? value { get; set; }
87+
public List<T>? added { get; set; }
88+
public List<T>? changed { get; set; }
89+
public List<T>? deleted { get; set; }
90+
public IDictionary<string, object>? @params { get; set; }
91+
}
92+
}
93+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace RemoteSaveAdaptor.Server.Controllers
4+
{
5+
[ApiController]
6+
[Route("[controller]")]
7+
public class WeatherForecastController : ControllerBase
8+
{
9+
private static readonly string[] Summaries = new[]
10+
{
11+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
12+
};
13+
14+
private readonly ILogger<WeatherForecastController> _logger;
15+
16+
public WeatherForecastController(ILogger<WeatherForecastController> logger)
17+
{
18+
_logger = logger;
19+
}
20+
21+
[HttpGet(Name = "GetWeatherForecast")]
22+
public IEnumerable<WeatherForecast> Get()
23+
{
24+
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
25+
{
26+
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
27+
TemperatureC = Random.Shared.Next(-20, 55),
28+
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
29+
})
30+
.ToArray();
31+
}
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace RemoteSaveAdaptor.Server.Models
4+
{
5+
public class OrdersDetails
6+
{
7+
public static List<OrdersDetails> order = new List<OrdersDetails>();
8+
public OrdersDetails()
9+
{
10+
11+
}
12+
public OrdersDetails(int OrderID, string CustomerId, int EmployeeId, double Freight, bool Verified, DateTime OrderDate, string ShipCity, string ShipName, string ShipCountry, DateTime ShippedDate, string ShipAddress)
13+
{
14+
this.OrderID = OrderID;
15+
this.CustomerID = CustomerId;
16+
this.EmployeeID = EmployeeId;
17+
this.Freight = Freight;
18+
this.ShipCity = ShipCity;
19+
this.Verified = Verified;
20+
this.OrderDate = OrderDate;
21+
this.ShipName = ShipName;
22+
this.ShipCountry = ShipCountry;
23+
this.ShippedDate = ShippedDate;
24+
this.ShipAddress = ShipAddress;
25+
}
26+
27+
public static List<OrdersDetails> GetAllRecords()
28+
{
29+
if (order.Count() == 0)
30+
{
31+
int code = 10000;
32+
for (int i = 1; i <= 2000; i++)
33+
{
34+
order.Add(new OrdersDetails(code + 1, "ALFKI", i + 0, 2.3 * i, false, new DateTime(1991, 05, 15), "Berlin", "Simons bistro", "Denmark", new DateTime(1996, 7, 16), "Kirchgasse 6"));
35+
order.Add(new OrdersDetails(code + 2, "ANATR", i + 2, 3.3 * i, true, new DateTime(1990, 04, 04), "Madrid", "Queen Cozinha", "Brazil", new DateTime(1996, 9, 11), "Avda. Azteca 123"));
36+
order.Add(new OrdersDetails(code + 3, "ANTON", i + 1, 4.3 * i, true, new DateTime(1957, 11, 30), "Cholchester", "Frankenversand", "Germany", new DateTime(1996, 10, 7), "Carrera 52 con Ave. Bolívar #65-98 Llano Largo"));
37+
order.Add(new OrdersDetails(code + 4, "BLONP", i + 3, 5.3 * i, false, new DateTime(1930, 10, 22), "Marseille", "Ernst Handel", "Austria", new DateTime(1996, 12, 30), "Magazinweg 7"));
38+
order.Add(new OrdersDetails(code + 5, "BOLID", i + 4, 6.3 * i, true, new DateTime(1953, 02, 18), "Tsawassen", "Hanari Carnes", "Switzerland", new DateTime(1997, 12, 3), "1029 - 12th Ave. S."));
39+
code += 5;
40+
}
41+
}
42+
return order;
43+
}
44+
[Key]
45+
public int OrderID { get; set; }
46+
public string? CustomerID { get; set; }
47+
public int? EmployeeID { get; set; }
48+
public double? Freight { get; set; }
49+
public string? ShipCity { get; set; }
50+
public bool? Verified { get; set; }
51+
public DateTime? OrderDate { get; set; }
52+
public string? ShipName { get; set; }
53+
public string? ShipCountry { get; set; }
54+
public DateTime? ShippedDate { get; set; }
55+
public string? ShipAddress { get; set; }
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
var builder = WebApplication.CreateBuilder(args);
2+
3+
// Add services to the container.
4+
5+
builder.Services.AddControllers();
6+
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
7+
builder.Services.AddEndpointsApiExplorer();
8+
builder.Services.AddSwaggerGen();
9+
builder.Services.AddCors(options =>
10+
{
11+
options.AddDefaultPolicy(builder =>
12+
{
13+
builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader();
14+
});
15+
});
16+
var app = builder.Build();
17+
app.UseCors();
18+
app.UseDefaultFiles();
19+
app.UseStaticFiles();
20+
21+
// Configure the HTTP request pipeline.
22+
if (app.Environment.IsDevelopment())
23+
{
24+
app.UseSwagger();
25+
app.UseSwaggerUI();
26+
}
27+
28+
app.UseHttpsRedirection();
29+
30+
app.UseAuthorization();
31+
32+
app.MapControllers();
33+
34+
app.MapFallbackToFile("/index.html");
35+
36+
app.Run();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:17668",
8+
"sslPort": 44357
9+
}
10+
},
11+
"profiles": {
12+
"http": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"launchUrl": "swagger",
17+
"applicationUrl": "http://localhost:5218",
18+
"environmentVariables": {
19+
"ASPNETCORE_ENVIRONMENT": "Development",
20+
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy"
21+
}
22+
},
23+
"https": {
24+
"commandName": "Project",
25+
"dotnetRunMessages": true,
26+
"launchBrowser": true,
27+
"launchUrl": "swagger",
28+
"applicationUrl": "https://localhost:7010;http://localhost:5218",
29+
"environmentVariables": {
30+
"ASPNETCORE_ENVIRONMENT": "Development",
31+
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy"
32+
}
33+
},
34+
"IIS Express": {
35+
"commandName": "IISExpress",
36+
"launchBrowser": true,
37+
"launchUrl": "swagger",
38+
"environmentVariables": {
39+
"ASPNETCORE_ENVIRONMENT": "Development",
40+
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy"
41+
}
42+
}
43+
}
44+
}
45+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<SpaRoot>..\remotesaveadaptor.client</SpaRoot>
8+
<SpaProxyLaunchCommand>npm start</SpaProxyLaunchCommand>
9+
<SpaProxyServerUrl>https://localhost:4200</SpaProxyServerUrl>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.AspNetCore.SpaProxy">
14+
<Version>8.*-*</Version>
15+
</PackageReference>
16+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<ProjectReference Include="..\remotesaveadaptor.client\remotesaveadaptor.client.esproj">
21+
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
22+
</ProjectReference>
23+
</ItemGroup>
24+
25+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ActiveDebugProfile>https</ActiveDebugProfile>
5+
<Controller_SelectedScaffolderID>ApiControllerEmptyScaffolder</Controller_SelectedScaffolderID>
6+
<Controller_SelectedScaffolderCategoryPath>root/Common/Api</Controller_SelectedScaffolderCategoryPath>
7+
</PropertyGroup>
8+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@RemoteSaveAdaptor.Server_HostAddress = http://localhost:5218
2+
3+
GET {{RemoteSaveAdaptor.Server_HostAddress}}/weatherforecast/
4+
Accept: application/json
5+
6+
###
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace RemoteSaveAdaptor.Server
2+
{
3+
public class WeatherForecast
4+
{
5+
public DateOnly Date { get; set; }
6+
7+
public int TemperatureC { get; set; }
8+
9+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
10+
11+
public string? Summary { get; set; }
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"AllowedHosts": "*"
9+
}
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.9.34728.123
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RemoteSaveAdaptor.Server", "RemoteSaveAdaptor.Server\RemoteSaveAdaptor.Server.csproj", "{03248ABA-27D2-470C-9FE2-6AF2F2F56A96}"
7+
EndProject
8+
Project("{54A90642-561A-4BB1-A94E-469ADEE60C69}") = "remotesaveadaptor.client", "remotesaveadaptor.client\remotesaveadaptor.client.esproj", "{F593DC32-452A-4342-9CBB-7C336F34F494}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{03248ABA-27D2-470C-9FE2-6AF2F2F56A96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{03248ABA-27D2-470C-9FE2-6AF2F2F56A96}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{03248ABA-27D2-470C-9FE2-6AF2F2F56A96}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{03248ABA-27D2-470C-9FE2-6AF2F2F56A96}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{F593DC32-452A-4342-9CBB-7C336F34F494}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{F593DC32-452A-4342-9CBB-7C336F34F494}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{F593DC32-452A-4342-9CBB-7C336F34F494}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
23+
{F593DC32-452A-4342-9CBB-7C336F34F494}.Release|Any CPU.ActiveCfg = Release|Any CPU
24+
{F593DC32-452A-4342-9CBB-7C336F34F494}.Release|Any CPU.Build.0 = Release|Any CPU
25+
{F593DC32-452A-4342-9CBB-7C336F34F494}.Release|Any CPU.Deploy.0 = Release|Any CPU
26+
EndGlobalSection
27+
GlobalSection(SolutionProperties) = preSolution
28+
HideSolutionNode = FALSE
29+
EndGlobalSection
30+
GlobalSection(ExtensibilityGlobals) = postSolution
31+
SolutionGuid = {C339D384-F8A0-4882-B45A-DAED514717FC}
32+
EndGlobalSection
33+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Editor configuration, see https://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.ts]
12+
quote_type = single
13+
14+
[*.md]
15+
max_line_length = off
16+
trim_trailing_whitespace = false

0 commit comments

Comments
 (0)