Skip to content

Commit 5fa29ca

Browse files
Adding sample for webmethodadaptor
1 parent bcbe1fb commit 5fa29ca

21 files changed

+4195
-0
lines changed

WebMethodAdaptor/WebMethodAdaptor.sln

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}") = "WebMethodAdaptor", "WebMethodAdaptor\WebMethodAdaptor.csproj", "{9E52133B-DAFC-42F9-8FE8-885C86A62980}"
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+
{9E52133B-DAFC-42F9-8FE8-885C86A62980}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{9E52133B-DAFC-42F9-8FE8-885C86A62980}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{9E52133B-DAFC-42F9-8FE8-885C86A62980}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{9E52133B-DAFC-42F9-8FE8-885C86A62980}.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 = {E5423815-B194-48EA-ACD6-6E8C9BC255F4}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Syncfusion.EJ2.Base;
3+
using WebMethodAdaptor.Models;
4+
5+
namespace WebMethodAdaptor.Server.Controllers
6+
{
7+
public class GridController : Controller
8+
{
9+
// method to retrieve data
10+
[HttpGet]
11+
[Route("api/[controller]")]
12+
public List<OrdersDetails> GetOrderData()
13+
{
14+
// Retrieve all records and convert to list
15+
var data = OrdersDetails.GetAllRecords().ToList();
16+
return data;
17+
}
18+
19+
// POST method to handle incoming data manager requests
20+
[HttpPost]
21+
[Route("api/[controller]")]
22+
public object Post([FromBody] DataManager DataManagerRequest)
23+
{
24+
// Retrieve data source and convert to queryable
25+
IQueryable<OrdersDetails> DataSource = GetOrderData().AsQueryable();
26+
27+
// Initialize QueryableOperation
28+
QueryableOperation queryableOperation = new QueryableOperation();
29+
30+
// Retrieve data manager value
31+
DataManagerRequest dataManagerParams = DataManagerRequest.Value;
32+
33+
34+
// Perform filtering operation if filtering is provided
35+
if (dataManagerParams.Where != null && dataManagerParams.Where.Count > 0)
36+
{
37+
DataSource = queryableOperation.PerformFiltering(DataSource, dataManagerParams.Where, dataManagerParams.Where[0].Operator);
38+
}
39+
40+
// Perform search operation if search is provided
41+
if (dataManagerParams.Search != null && dataManagerParams.Search.Count > 0)
42+
{
43+
DataSource = queryableOperation.PerformSearching(DataSource, dataManagerParams.Search);
44+
}
45+
46+
// Perform sorting operation if sorting is provided
47+
if (dataManagerParams.Sorted != null && dataManagerParams.Sorted.Count > 0)
48+
{
49+
DataSource = queryableOperation.PerformSorting(DataSource, dataManagerParams.Sorted);
50+
}
51+
52+
// Get total record count after applying filters
53+
int totalRecordsCount = DataSource.Count();
54+
55+
// Perform skip operation if skip value is provided
56+
if (dataManagerParams.Skip != 0)
57+
{
58+
DataSource = queryableOperation.PerformSkip(DataSource, dataManagerParams.Skip);
59+
}
60+
61+
// Perform take operation if take value is provided
62+
if (dataManagerParams.Take != 0)
63+
{
64+
DataSource = queryableOperation.PerformTake(DataSource, dataManagerParams.Take);
65+
}
66+
67+
// Return result and total record count
68+
return new { result = DataSource, count = totalRecordsCount };
69+
}
70+
71+
// POST method to handle record insertion
72+
[HttpPost]
73+
[Route("api/[controller]/Insert")]
74+
public void Insert([FromBody] CRUDModel<OrdersDetails> newRecord)
75+
{
76+
// Check if new record is not null
77+
if (newRecord.value != null)
78+
{
79+
// Insert new record
80+
OrdersDetails.GetAllRecords().Insert(0, newRecord.value);
81+
}
82+
}
83+
84+
// POST method to handle record updates
85+
[HttpPost]
86+
[Route("api/[controller]/Update")]
87+
public void Update([FromBody] CRUDModel<OrdersDetails> updatedRecord)
88+
{
89+
// Retrieve updated order
90+
var updatedOrder = updatedRecord.value;
91+
if (updatedOrder != null)
92+
{
93+
// Find existing record
94+
var data = OrdersDetails.GetAllRecords().FirstOrDefault(or => or.OrderID == updatedOrder.OrderID);
95+
if (data != null)
96+
{
97+
// Update existing record
98+
data.OrderID = updatedOrder.OrderID;
99+
data.CustomerID = updatedOrder.CustomerID;
100+
data.ShipCity = updatedOrder.ShipCity;
101+
data.ShipCountry = updatedOrder.ShipCountry;
102+
// Update other properties similarly
103+
}
104+
}
105+
}
106+
107+
// POST method to handle record removal
108+
[HttpPost]
109+
[Route("api/[controller]/Remove")]
110+
public void Remove([FromBody] CRUDModel<OrdersDetails> deletedRecord)
111+
{
112+
// Retrieve order ID from deleted record
113+
int orderId = int.Parse(deletedRecord.key.ToString());
114+
// Find record to delete
115+
var data = OrdersDetails.GetAllRecords().FirstOrDefault(orderData => orderData.OrderID == orderId);
116+
if (data != null)
117+
{
118+
// Remove record from data collection
119+
OrdersDetails.GetAllRecords().Remove(data);
120+
}
121+
}
122+
123+
[HttpPost]
124+
[Route("api/[controller]/CrudUpdate")]
125+
public void CrudUpdate([FromBody] CRUDModel<OrdersDetails> request)
126+
{
127+
// perform update operation
128+
if (request.action == "update")
129+
{
130+
var orderValue = request.value;
131+
OrdersDetails existingRecord = OrdersDetails.GetAllRecords().Where(or => or.OrderID == orderValue.OrderID).FirstOrDefault();
132+
existingRecord.OrderID = orderValue.OrderID;
133+
existingRecord.CustomerID = orderValue.CustomerID;
134+
existingRecord.ShipCity = orderValue.ShipCity;
135+
}
136+
// perform insert operation
137+
else if (request.action == "insert")
138+
{
139+
OrdersDetails.GetAllRecords().Insert(0, request.value);
140+
}
141+
// perform remove operation
142+
else if (request.action == "remove")
143+
{
144+
OrdersDetails.GetAllRecords().Remove(OrdersDetails.GetAllRecords().Where(or => or.OrderID == int.Parse(request.key.ToString())).FirstOrDefault());
145+
}
146+
}
147+
[HttpPost]
148+
[Route("api/[controller]/BatchUpdate")]
149+
public IActionResult BatchUpdate([FromBody] CRUDModel<OrdersDetails> batchOperation)
150+
{
151+
if (batchOperation.added != null)
152+
{
153+
foreach (var addedOrder in batchOperation.added)
154+
{
155+
OrdersDetails.GetAllRecords().Insert(0, addedOrder);
156+
}
157+
}
158+
if (batchOperation.changed != null)
159+
{
160+
foreach (var changedOrder in batchOperation.changed)
161+
{
162+
var existingOrder = OrdersDetails.GetAllRecords().FirstOrDefault(or => or.OrderID == changedOrder.OrderID);
163+
if (existingOrder != null)
164+
{
165+
existingOrder.CustomerID = changedOrder.CustomerID;
166+
existingOrder.ShipCity = changedOrder.ShipCity;
167+
// Update other properties as needed
168+
}
169+
}
170+
}
171+
if (batchOperation.deleted != null)
172+
{
173+
foreach (var deletedOrder in batchOperation.deleted)
174+
{
175+
var orderToDelete = OrdersDetails.GetAllRecords().FirstOrDefault(or => or.OrderID == deletedOrder.OrderID);
176+
if (orderToDelete != null)
177+
{
178+
OrdersDetails.GetAllRecords().Remove(orderToDelete);
179+
}
180+
}
181+
}
182+
return Json(batchOperation);
183+
}
184+
// Model for handling data manager requests
185+
public class DataManager
186+
{
187+
public required DataManagerRequest Value { get; set; }
188+
}
189+
190+
// Model for handling CRUD operations
191+
public class CRUDModel<T> where T : class
192+
{
193+
public string? action { get; set; }
194+
public string? keyColumn { get; set; }
195+
public object? key { get; set; }
196+
public T? value { get; set; }
197+
public List<T>? added { get; set; }
198+
public List<T>? changed { get; set; }
199+
public List<T>? deleted { get; set; }
200+
public IDictionary<string, object>? @params { get; set; }
201+
}
202+
203+
}
204+
}
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 WebMethodAdaptor.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: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
namespace WebMethodAdaptor.Models
2+
{
3+
public class OrdersDetails
4+
{
5+
public static List<OrdersDetails> order = new List<OrdersDetails>();
6+
public OrdersDetails()
7+
{
8+
9+
}
10+
public OrdersDetails(
11+
int OrderID, string CustomerId, int EmployeeId, double Freight, bool Verified,
12+
DateTime OrderDate, string ShipCity, string ShipName, string ShipCountry,
13+
DateTime ShippedDate, string ShipAddress)
14+
{
15+
this.OrderID = OrderID;
16+
this.CustomerID = CustomerId;
17+
this.EmployeeID = EmployeeId;
18+
this.Freight = Freight;
19+
this.ShipCity = ShipCity;
20+
this.Verified = Verified;
21+
this.OrderDate = OrderDate;
22+
this.ShipName = ShipName;
23+
this.ShipCountry = ShipCountry;
24+
this.ShippedDate = ShippedDate;
25+
this.ShipAddress = ShipAddress;
26+
}
27+
28+
public static List<OrdersDetails> GetAllRecords()
29+
{
30+
if (order.Count() == 0)
31+
{
32+
int code = 10000;
33+
for (int i = 1; i < 10; i++)
34+
{
35+
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"));
36+
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"));
37+
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"));
38+
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"));
39+
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."));
40+
code += 5;
41+
}
42+
}
43+
return order;
44+
}
45+
46+
public int? OrderID { get; set; }
47+
public string? CustomerID { get; set; }
48+
public int? EmployeeID { get; set; }
49+
public double? Freight { get; set; }
50+
public string? ShipCity { get; set; }
51+
public bool? Verified { get; set; }
52+
public DateTime OrderDate { get; set; }
53+
public string? ShipName { get; set; }
54+
public string? ShipCountry { get; set; }
55+
public DateTime ShippedDate { get; set; }
56+
public string? ShipAddress { get; set; }
57+
}
58+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
// Configure the HTTP request pipeline.
13+
if (app.Environment.IsDevelopment())
14+
{
15+
app.UseSwagger();
16+
app.UseSwaggerUI();
17+
}
18+
19+
app.UseDefaultFiles();
20+
app.UseStaticFiles();
21+
22+
app.UseHttpsRedirection();
23+
24+
app.UseAuthorization();
25+
26+
app.MapControllers();
27+
28+
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:39928",
8+
"sslPort": 44304
9+
}
10+
},
11+
"profiles": {
12+
"http": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"launchUrl": "swagger",
17+
"applicationUrl": "http://localhost:5148",
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:7233;http://localhost:5148",
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+
}

0 commit comments

Comments
 (0)