Skip to content

Commit 69eda7d

Browse files
Perform data and CRUD operation in ej2 angular grid using UrlAdaptor
1 parent b9e3bd5 commit 69eda7d

File tree

11 files changed

+56
-133
lines changed

11 files changed

+56
-133
lines changed

.github/workflows/gitleaks.yaml

Lines changed: 0 additions & 38 deletions
This file was deleted.

URLAdaptor.sln

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,31 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.9.34701.34
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UrlAdaptor.Server", "UrlAdaptor.Server\UrlAdaptor.Server.csproj", "{E505D196-CD36-4E00-955C-FED93626BBC3}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UrlAdaptor.Server", "UrlAdaptor.Server\UrlAdaptor.Server.csproj", "{172FA896-7156-482D-B357-56B57C2ACC2E}"
77
EndProject
8-
Project("{54A90642-561A-4BB1-A94E-469ADEE60C69}") = "urladaptor.client", "urladaptor.client\urladaptor.client.esproj", "{59902233-CD64-41CF-9F3E-FCB644873669}"
8+
Project("{54A90642-561A-4BB1-A94E-469ADEE60C69}") = "urladaptor.client", "urladaptor.client\urladaptor.client.esproj", "{FEA97C46-317C-4D4E-8193-DE0F916A55AC}"
99
EndProject
1010
Global
1111
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1212
Debug|Any CPU = Debug|Any CPU
1313
Release|Any CPU = Release|Any CPU
1414
EndGlobalSection
1515
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16-
{E505D196-CD36-4E00-955C-FED93626BBC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17-
{E505D196-CD36-4E00-955C-FED93626BBC3}.Debug|Any CPU.Build.0 = Debug|Any CPU
18-
{E505D196-CD36-4E00-955C-FED93626BBC3}.Release|Any CPU.ActiveCfg = Release|Any CPU
19-
{E505D196-CD36-4E00-955C-FED93626BBC3}.Release|Any CPU.Build.0 = Release|Any CPU
20-
{59902233-CD64-41CF-9F3E-FCB644873669}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21-
{59902233-CD64-41CF-9F3E-FCB644873669}.Debug|Any CPU.Build.0 = Debug|Any CPU
22-
{59902233-CD64-41CF-9F3E-FCB644873669}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
23-
{59902233-CD64-41CF-9F3E-FCB644873669}.Release|Any CPU.ActiveCfg = Release|Any CPU
24-
{59902233-CD64-41CF-9F3E-FCB644873669}.Release|Any CPU.Build.0 = Release|Any CPU
25-
{59902233-CD64-41CF-9F3E-FCB644873669}.Release|Any CPU.Deploy.0 = Release|Any CPU
16+
{172FA896-7156-482D-B357-56B57C2ACC2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{172FA896-7156-482D-B357-56B57C2ACC2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{172FA896-7156-482D-B357-56B57C2ACC2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{172FA896-7156-482D-B357-56B57C2ACC2E}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{FEA97C46-317C-4D4E-8193-DE0F916A55AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{FEA97C46-317C-4D4E-8193-DE0F916A55AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{FEA97C46-317C-4D4E-8193-DE0F916A55AC}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
23+
{FEA97C46-317C-4D4E-8193-DE0F916A55AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
24+
{FEA97C46-317C-4D4E-8193-DE0F916A55AC}.Release|Any CPU.Build.0 = Release|Any CPU
25+
{FEA97C46-317C-4D4E-8193-DE0F916A55AC}.Release|Any CPU.Deploy.0 = Release|Any CPU
2626
EndGlobalSection
2727
GlobalSection(SolutionProperties) = preSolution
2828
HideSolutionNode = FALSE
2929
EndGlobalSection
3030
GlobalSection(ExtensibilityGlobals) = postSolution
31-
SolutionGuid = {7F60DE0A-FC66-4C0B-8CBA-34877FA505B4}
31+
SolutionGuid = {2065418E-5D4B-4B3A-9F5B-5A39B535109B}
3232
EndGlobalSection
3333
EndGlobal

UrlAdaptor.Server/Controllers/GridController.cs

Lines changed: 16 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
using Microsoft.AspNetCore.Http;
22
using Microsoft.AspNetCore.Mvc;
3-
using Syncfusion.EJ2.Base;
43
using UrlAdaptor.Server.Models;
5-
4+
using Syncfusion.EJ2.Base;
65

76
namespace UrlAdaptor.Server.Controllers
87
{
@@ -16,9 +15,10 @@ public object Post([FromBody] DataManagerRequest DataManagerRequest)
1615
// Retrieve data from the data source (e.g., database)
1716
IQueryable<OrdersDetails> DataSource = GetOrderData().AsQueryable();
1817

19-
QueryableOperation queryableOperation = new QueryableOperation(); // Initialize DataOperations instance
18+
QueryableOperation queryableOperation = new QueryableOperation(); // Initialize QueryableOperation instance
19+
2020

21-
// Handling searching operation
21+
// Handling Searching operation
2222
if (DataManagerRequest.Search != null && DataManagerRequest.Search.Count > 0)
2323
{
2424
DataSource = queryableOperation.PerformSearching(DataSource, DataManagerRequest.Search);
@@ -36,7 +36,7 @@ public object Post([FromBody] DataManagerRequest DataManagerRequest)
3636
}
3737
}
3838

39-
// Handling sorting operation
39+
// Handling Sorting operation
4040
if (DataManagerRequest.Sorted != null && DataManagerRequest.Sorted.Count > 0)
4141
{
4242
DataSource = queryableOperation.PerformSorting(DataSource, DataManagerRequest.Sorted);
@@ -48,13 +48,13 @@ public object Post([FromBody] DataManagerRequest DataManagerRequest)
4848
// Handling paging operation.
4949
if (DataManagerRequest.Skip != 0)
5050
{
51+
// Paging
5152
DataSource = queryableOperation.PerformSkip(DataSource, DataManagerRequest.Skip);
5253
}
5354
if (DataManagerRequest.Take != 0)
5455
{
5556
DataSource = queryableOperation.PerformTake(DataSource, DataManagerRequest.Take);
5657
}
57-
5858
// Return data based on the request
5959
return new { result = DataSource, count = totalRecordsCount };
6060
}
@@ -78,7 +78,7 @@ public void Insert([FromBody] CRUDModel<OrdersDetails> newRecord)
7878
{
7979
if (newRecord.value != null)
8080
{
81-
OrdersDetails.GetAllRecords().Insert(0, newRecord.value);
81+
OrdersDetails.GetAllRecords().Insert(0, newRecord.value);
8282
}
8383
}
8484

@@ -105,8 +105,8 @@ public void Update([FromBody] CRUDModel<OrdersDetails> Order)
105105
// Update other properties similarly
106106
}
107107
}
108-
109108
}
109+
110110
/// <summary>
111111
/// Remove a specific data item from the data collection.
112112
/// </summary>
@@ -116,7 +116,7 @@ public void Update([FromBody] CRUDModel<OrdersDetails> Order)
116116
[Route("api/Grid/Remove")]
117117
public void Remove([FromBody] CRUDModel<OrdersDetails> value)
118118
{
119-
int orderId = int.Parse((value.key).ToString());
119+
int orderId = int.Parse(value.key.ToString());
120120
var data = OrdersDetails.GetAllRecords().FirstOrDefault(orderData => orderData.OrderID == orderId);
121121
if (data != null)
122122
{
@@ -125,63 +125,25 @@ public void Remove([FromBody] CRUDModel<OrdersDetails> value)
125125
}
126126
}
127127

128-
/// <summary>
129-
/// 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.
130-
/// </summary>
131-
/// <param name="request"></param>
132-
[HttpPost]
133-
[Route("api/[controller]/CrudUpdate")]
134-
public void CrudUpdate([FromBody] CRUDModel<OrdersDetails> request)
135-
{
136-
// Update record
137-
if (request.action == "update")
138-
{
139-
var orderValue = request.value;
140-
OrdersDetails existingRecord = OrdersDetails.GetAllRecords().FirstOrDefault(or => or.OrderID == orderValue.OrderID);
141-
142-
if (orderValue !=null && existingRecord !=null)
143-
{
144-
existingRecord.OrderID = orderValue.OrderID;
145-
existingRecord.CustomerID = orderValue.CustomerID;
146-
existingRecord.ShipCity = orderValue.ShipCity;
147-
}
148-
149-
}
150-
// Insert record
151-
else if (request.action == "insert")
152-
{
153-
if (request.value != null)
154-
{
155-
OrdersDetails.GetAllRecords().Insert(0, request.value);
156-
}
157-
}
158-
// Delete record
159-
else if (request.action == "remove")
160-
{
161-
OrdersDetails.GetAllRecords().Remove(OrdersDetails.GetAllRecords().FirstOrDefault(or => or.OrderID == int.Parse(request.key.ToString())));
162-
}
163-
164-
}
165-
166128

167129
public class CRUDModel<T> where T : class
168130
{
169131

170132
public string? action { get; set; }
171-
133+
172134
public string? keyColumn { get; set; }
173-
135+
174136
public object? key { get; set; }
175-
137+
176138
public T? value { get; set; }
177139

178140
public List<T>? added { get; set; }
179-
141+
180142
public List<T>? changed { get; set; }
181-
143+
182144
public List<T>? deleted { get; set; }
183-
145+
184146
public IDictionary<string, object>? @params { get; set; }
185147
}
186148
}
187-
}
149+
}

UrlAdaptor.Server/Models/OrdersDetails.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ public static List<OrdersDetails> GetAllRecords()
5555
public DateTime ShippedDate { get; set; }
5656
public string? ShipAddress { get; set; }
5757
}
58-
}
58+
}

UrlAdaptor.Server/Program.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
var builder = WebApplication.CreateBuilder(args);
22

33
// Add services to the container.
4-
builder.Services.AddCors(options =>
4+
5+
builder.Services.AddControllers().AddJsonOptions(options =>
56
{
6-
options.AddDefaultPolicy(builder =>
7-
{
8-
builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader();
9-
});
7+
options.JsonSerializerOptions.PropertyNamingPolicy = null; // Use PascalCase
108
});
11-
129
builder.Services.AddControllers();
1310
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
1411
builder.Services.AddEndpointsApiExplorer();
1512
builder.Services.AddSwaggerGen();
1613

14+
builder.Services.AddCors(options =>
15+
{
16+
options.AddDefaultPolicy(builder =>
17+
{
18+
builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader();
19+
});
20+
});
1721
var app = builder.Build();
18-
1922
app.UseCors();
23+
2024
app.UseDefaultFiles();
2125
app.UseStaticFiles();
2226

UrlAdaptor.Server/Properties/launchSettings.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@
99
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy"
1010
},
1111
"dotnetRunMessages": true,
12-
"applicationUrl": "http://localhost:5147"
12+
"applicationUrl": "http://localhost:5102"
1313
},
1414
"https": {
1515
"commandName": "Project",
16-
"launchBrowser": true,
1716
"launchUrl": "swagger",
1817
"environmentVariables": {
1918
"ASPNETCORE_ENVIRONMENT": "Development",
2019
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy"
2120
},
2221
"dotnetRunMessages": true,
23-
"applicationUrl": "https://localhost:7233;http://localhost:5147"
22+
"applicationUrl": "https://localhost:7018;http://localhost:5102"
2423
},
2524
"IIS Express": {
2625
"commandName": "IISExpress",
@@ -37,8 +36,8 @@
3736
"windowsAuthentication": false,
3837
"anonymousAuthentication": true,
3938
"iisExpress": {
40-
"applicationUrl": "http://localhost:14359",
41-
"sslPort": 44322
39+
"applicationUrl": "http://localhost:63721",
40+
"sslPort": 44363
4241
}
4342
}
4443
}

UrlAdaptor.Server/UrlAdaptor.Server.csproj.user

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,4 @@
55
<Controller_SelectedScaffolderID>ApiControllerEmptyScaffolder</Controller_SelectedScaffolderID>
66
<Controller_SelectedScaffolderCategoryPath>root/Common/Api</Controller_SelectedScaffolderCategoryPath>
77
</PropertyGroup>
8-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
9-
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
10-
</PropertyGroup>
118
</Project>

UrlAdaptor.Server/UrlAdaptor.Server.http

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@UrlAdaptor.Server_HostAddress = http://localhost:5147
1+
@UrlAdaptor.Server_HostAddress = http://localhost:5102
22

33
GET {{UrlAdaptor.Server_HostAddress}}/weatherforecast/
44
Accept: application/json

urladaptor.client/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"@angular/platform-browser": "^17.2.0",
2222
"@angular/platform-browser-dynamic": "^17.2.0",
2323
"@angular/router": "^17.2.0",
24-
"@syncfusion/ej2-angular-grids": "^24.2.9",
25-
"@syncfusion/ej2-data": "^24.2.3",
24+
"@syncfusion/ej2-angular-grids": "^25.1.35",
25+
"@syncfusion/ej2-data": "^25.1.35",
2626
"jest-editor-support": "*",
2727
"run-script-os": "*",
2828
"rxjs": "~7.8.0",

urladaptor.client/src/app/app.component.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ export class AppComponent {
1616

1717
ngOnInit(): void {
1818
this.data = new DataManager({
19-
url: 'https://localhost:7233/api/grid', // Replace your hosted link
20-
insertUrl: 'https://localhost:7233/api/grid/Insert',
21-
updateUrl: 'https://localhost:7233/api/grid/Update',
22-
removeUrl: 'https://localhost:7233/api/grid/Remove',
23-
//crudUrl:'https://localhost:7233/api/grid/CrudUpdate',
24-
//batchUrl:'https://localhost:7233/api/grid/BatchUpdate',
19+
url: 'https://localhost:7018/api/grid', // Replace your hosted link
20+
insertUrl: 'https://localhost:7018/api/grid/Insert',
21+
updateUrl: 'https://localhost:7018/api/grid/Update',
22+
removeUrl: 'https://localhost:7018/api/grid/Remove',
23+
//crudUrl:'https://localhost:7018/api/grid/CrudUpdate',
24+
//batchUrl:'https://localhost:7018/api/grid/BatchUpdate',
2525
adaptor: new UrlAdaptor()
2626
});
27-
this.toolbar = ['Add', 'Edit', 'Update', 'Delete', 'Cancel','Search'];
27+
this.toolbar = ['Add', 'Update', 'Delete', 'Cancel', 'Search'];
2828
this.editSettings = { allowAdding: true, allowDeleting: true, allowEditing: true, mode: 'Normal' };
2929
}
3030
}

0 commit comments

Comments
 (0)