Skip to content

Commit d505bf6

Browse files
Adding sample for RemoteSaveAdaptor
1 parent 21b0fe6 commit d505bf6

14 files changed

+406
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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", "RemoteSaveAdaptor\RemoteSaveAdaptor.csproj", "{195AC7C8-3117-493B-8DA1-CA6F5764AB65}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{195AC7C8-3117-493B-8DA1-CA6F5764AB65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{195AC7C8-3117-493B-8DA1-CA6F5764AB65}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{195AC7C8-3117-493B-8DA1-CA6F5764AB65}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{195AC7C8-3117-493B-8DA1-CA6F5764AB65}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {6C46EAAC-6A39-444D-B3CB-DC9AFD316546}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using RemoteSaveAdaptor.Models;
3+
4+
namespace RemoteSaveAdaptor.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+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace RemoteSaveAdaptor.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+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace RemoteSaveAdaptor.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+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
10+
var app = builder.Build();
11+
12+
app.UseDefaultFiles();
13+
app.UseStaticFiles();
14+
// Configure the HTTP request pipeline.
15+
if (app.Environment.IsDevelopment())
16+
{
17+
app.UseSwagger();
18+
app.UseSwaggerUI();
19+
}
20+
21+
app.UseHttpsRedirection();
22+
23+
app.UseAuthorization();
24+
25+
app.MapControllers();
26+
27+
app.Run();
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:2914",
8+
"sslPort": 44380
9+
}
10+
},
11+
"profiles": {
12+
"http": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"launchUrl": "swagger",
17+
"applicationUrl": "http://localhost:5151",
18+
"environmentVariables": {
19+
"ASPNETCORE_ENVIRONMENT": "Development"
20+
}
21+
},
22+
"https": {
23+
"commandName": "Project",
24+
"dotnetRunMessages": true,
25+
"launchBrowser": true,
26+
//"launchUrl": "swagger",
27+
"applicationUrl": "https://localhost:7035;http://localhost:5151",
28+
"environmentVariables": {
29+
"ASPNETCORE_ENVIRONMENT": "Development"
30+
}
31+
},
32+
"IIS Express": {
33+
"commandName": "IISExpress",
34+
"launchBrowser": true,
35+
"launchUrl": "swagger",
36+
"environmentVariables": {
37+
"ASPNETCORE_ENVIRONMENT": "Development"
38+
}
39+
}
40+
}
41+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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+
</PropertyGroup>
6+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@RemoteSaveAdaptor_HostAddress = http://localhost:5151
2+
3+
GET {{RemoteSaveAdaptor_HostAddress}}/weatherforecast/
4+
Accept: application/json
5+
6+
###
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace RemoteSaveAdaptor
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+
}
Lines changed: 8 additions & 0 deletions
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+
}
Lines changed: 9 additions & 0 deletions
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+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>EJ2 Grid</title>
5+
<meta charset="utf-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<meta name="description" content="Javascript Grid Control">
8+
<meta name="author" content="Syncfusion">
9+
<!--<link href="css/index.css" rel="stylesheet">-->
10+
<link href="https://cdn.syncfusion.com/ej2/26.1.35/ej2-base/styles/material.css" rel="stylesheet">
11+
<link href="https://cdn.syncfusion.com/ej2/26.1.35/ej2-grids/styles/material.css" rel="stylesheet">
12+
<link href="https://cdn.syncfusion.com/ej2/26.1.35/ej2-buttons/styles/material.css" rel="stylesheet">
13+
<link href="https://cdn.syncfusion.com/ej2/26.1.35/ej2-popups/styles/material.css" rel="stylesheet">
14+
<link href="https://cdn.syncfusion.com/ej2/26.1.35/ej2-richtexteditor/styles/material.css" rel="stylesheet">
15+
<link href="https://cdn.syncfusion.com/ej2/26.1.35/ej2-navigations/styles/material.css" rel="stylesheet">
16+
<link href="https://cdn.syncfusion.com/ej2/26.1.35/ej2-dropdowns/styles/material.css" rel="stylesheet">
17+
<link href="https://cdn.syncfusion.com/ej2/26.1.35/ej2-lists/styles/material.css" rel="stylesheet">
18+
<link href="https://cdn.syncfusion.com/ej2/26.1.35/ej2-inputs/styles/material.css" rel="stylesheet">
19+
<link href="https://cdn.syncfusion.com/ej2/26.1.35/ej2-calendars/styles/material.css" rel="stylesheet">
20+
<link href="https://cdn.syncfusion.com/ej2/26.1.35/ej2-notifications/styles/material.css" rel="stylesheet">
21+
<link href="https://cdn.syncfusion.com/ej2/26.1.35/ej2-splitbuttons/styles/material.css" rel="stylesheet">
22+
23+
<script src="https://cdn.syncfusion.com/ej2/26.1.35/dist/ej2.min.js" type="text/javascript"></script>
24+
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type="text/javascript"></script>
25+
</head>
26+
<body>
27+
28+
<div id="container">
29+
<div id="Grid"></div>
30+
</div>
31+
<script src="js/index.js" type="text/javascript"></script>
32+
</body>
33+
</html>

0 commit comments

Comments
 (0)