Skip to content

Commit 557e67f

Browse files
Adding sample for urladaptor
1 parent 5fa29ca commit 557e67f

21 files changed

+4215
-0
lines changed

UrlAdaptor/UrlAdaptor.sln

+25
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}") = "UrlAdaptor", "UrlAdaptor\UrlAdaptor.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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
using Microsoft.AspNetCore.Http;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Syncfusion.EJ2.Base;
4+
using UrlAdaptor.Models;
5+
6+
namespace UrlAdaptor.Controllers
7+
{
8+
[ApiController]
9+
public class GridController : Controller
10+
{
11+
[HttpPost]
12+
[Route("api/[controller]")]
13+
public object Post([FromBody] DataManagerRequest DataManagerRequest)
14+
{
15+
// Retrieve data from the data source (e.g., database)
16+
IQueryable<OrdersDetails> DataSource = GetOrderData().AsQueryable();
17+
18+
QueryableOperation queryableOperation = new QueryableOperation(); // Initialize DataOperations instance
19+
20+
// Handling searching operation
21+
if (DataManagerRequest.Search != null && DataManagerRequest.Search.Count > 0)
22+
{
23+
DataSource = queryableOperation.PerformSearching(DataSource, DataManagerRequest.Search);
24+
}
25+
26+
// Handling filtering operation
27+
if (DataManagerRequest.Where != null && DataManagerRequest.Where.Count > 0)
28+
{
29+
foreach (var condition in DataManagerRequest.Where)
30+
{
31+
foreach (var predicate in condition.predicates)
32+
{
33+
DataSource = queryableOperation.PerformFiltering(DataSource, DataManagerRequest.Where, predicate.Operator);
34+
}
35+
}
36+
}
37+
38+
// Handling sorting operation
39+
if (DataManagerRequest.Sorted != null && DataManagerRequest.Sorted.Count > 0)
40+
{
41+
DataSource = queryableOperation.PerformSorting(DataSource, DataManagerRequest.Sorted);
42+
}
43+
44+
// Get the total count of records
45+
int totalRecordsCount = DataSource.Count();
46+
47+
// Handling paging operation.
48+
if (DataManagerRequest.Skip != 0)
49+
{
50+
DataSource = queryableOperation.PerformSkip(DataSource, DataManagerRequest.Skip);
51+
}
52+
if (DataManagerRequest.Take != 0)
53+
{
54+
DataSource = queryableOperation.PerformTake(DataSource, DataManagerRequest.Take);
55+
}
56+
57+
// Return data based on the request
58+
return new { result = DataSource, count = totalRecordsCount };
59+
}
60+
61+
[HttpGet]
62+
[Route("api/[controller]")]
63+
public List<OrdersDetails> GetOrderData()
64+
{
65+
var data = OrdersDetails.GetAllRecords().ToList();
66+
return data;
67+
}
68+
69+
/// <summary>
70+
/// Inserts a new data item into the data collection.
71+
/// </summary>
72+
/// <param name="newRecord">It contains the new record detail which is need to be inserted.</param>
73+
/// <returns>Returns void</returns>
74+
[HttpPost]
75+
[Route("api/Grid/Insert")]
76+
public void Insert([FromBody] CRUDModel<OrdersDetails> newRecord)
77+
{
78+
if (newRecord.value != null)
79+
{
80+
OrdersDetails.GetAllRecords().Insert(0, newRecord.value);
81+
}
82+
}
83+
84+
/// <summary>
85+
/// Update a existing data item from the data collection.
86+
/// </summary>
87+
/// <param name="Order">It contains the updated record detail which is need to be updated.</param>
88+
/// <returns>Returns void</returns>
89+
[HttpPost]
90+
[Route("api/Grid/Update")]
91+
public void Update([FromBody] CRUDModel<OrdersDetails> Order)
92+
{
93+
var updatedOrder = Order.value;
94+
if (updatedOrder != null)
95+
{
96+
var data = OrdersDetails.GetAllRecords().FirstOrDefault(or => or.OrderID == updatedOrder.OrderID);
97+
if (data != null)
98+
{
99+
// Update the existing record
100+
data.OrderID = updatedOrder.OrderID;
101+
data.CustomerID = updatedOrder.CustomerID;
102+
data.ShipCity = updatedOrder.ShipCity;
103+
data.ShipCountry = updatedOrder.ShipCountry;
104+
// Update other properties similarly
105+
}
106+
}
107+
108+
}
109+
/// <summary>
110+
/// Remove a specific data item from the data collection.
111+
/// </summary>
112+
/// <param name="value">It contains the specific record detail which is need to be removed.</param>
113+
/// <return>Returns void</return>
114+
[HttpPost]
115+
[Route("api/Grid/Remove")]
116+
public void Remove([FromBody] CRUDModel<OrdersDetails> value)
117+
{
118+
int orderId = int.Parse((value.key).ToString());
119+
var data = OrdersDetails.GetAllRecords().FirstOrDefault(orderData => orderData.OrderID == orderId);
120+
if (data != null)
121+
{
122+
// Remove the record from the data collection
123+
OrdersDetails.GetAllRecords().Remove(data);
124+
}
125+
}
126+
127+
/// <summary>
128+
/// Perform all the CRUD operation at server-side using a single method instead of specifying separate controller action method for CRUD (insert, update and delete) operations.
129+
/// </summary>
130+
/// <param name="request"></param>
131+
[HttpPost]
132+
[Route("api/[controller]/CrudUpdate")]
133+
public void CrudUpdate([FromBody] CRUDModel<OrdersDetails> request)
134+
{
135+
if (request.action == "update")
136+
{
137+
// Update record
138+
var orderValue = request.value;
139+
OrdersDetails existingRecord = OrdersDetails.GetAllRecords().FirstOrDefault(or => or.OrderID == orderValue.OrderID);
140+
141+
if (orderValue != null && existingRecord != null)
142+
{
143+
existingRecord.OrderID = orderValue.OrderID;
144+
existingRecord.CustomerID = orderValue.CustomerID;
145+
existingRecord.ShipCity = orderValue.ShipCity;
146+
}
147+
148+
}
149+
else if (request.action == "insert")
150+
{
151+
// Insert record
152+
if (request.value != null)
153+
{
154+
OrdersDetails.GetAllRecords().Insert(0, request.value);
155+
}
156+
}
157+
else if (request.action == "remove")
158+
{
159+
// Delete record
160+
OrdersDetails.GetAllRecords().Remove(OrdersDetails.GetAllRecords().FirstOrDefault(or => or.OrderID == int.Parse(request.key.ToString())));
161+
}
162+
163+
}
164+
[HttpPost]
165+
[Route("api/[controller]/BatchUpdate")]
166+
public IActionResult BatchUpdate([FromBody] CRUDModel<OrdersDetails> batchmodel)
167+
{
168+
if (batchmodel.added != null)
169+
{
170+
foreach (var addedOrder in batchmodel.added)
171+
{
172+
OrdersDetails.GetAllRecords().Insert(0, addedOrder);
173+
}
174+
}
175+
if (batchmodel.changed != null)
176+
{
177+
foreach (var changedOrder in batchmodel.changed)
178+
{
179+
var existingOrder = OrdersDetails.GetAllRecords().FirstOrDefault(or => or.OrderID == changedOrder.OrderID);
180+
if (existingOrder != null)
181+
{
182+
existingOrder.CustomerID = changedOrder.CustomerID;
183+
existingOrder.ShipCity = changedOrder.ShipCity;
184+
existingOrder.ShipCountry = changedOrder.ShipCountry;
185+
// Update other properties as needed
186+
}
187+
}
188+
}
189+
if (batchmodel.deleted != null)
190+
{
191+
foreach (var deletedOrder in batchmodel.deleted)
192+
{
193+
var orderToDelete = OrdersDetails.GetAllRecords().FirstOrDefault(or => or.OrderID == deletedOrder.OrderID);
194+
if (orderToDelete != null)
195+
{
196+
OrdersDetails.GetAllRecords().Remove(orderToDelete);
197+
}
198+
}
199+
}
200+
return Json(batchmodel);
201+
}
202+
203+
204+
public class CRUDModel<T> where T : class
205+
{
206+
207+
public string? action { get; set; }
208+
209+
public string? keyColumn { get; set; }
210+
211+
public object? key { get; set; }
212+
213+
public T? value { get; set; }
214+
215+
public List<T>? added { get; set; }
216+
217+
public List<T>? changed { get; set; }
218+
219+
public List<T>? deleted { get; set; }
220+
221+
public IDictionary<string, object>? @params { get; set; }
222+
}
223+
}
224+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace UrlAdaptor.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,58 @@
1+
namespace UrlAdaptor.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+
}

UrlAdaptor/UrlAdaptor/Program.cs

+28
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();

0 commit comments

Comments
 (0)