Skip to content

Commit 6f2ac2d

Browse files
Updated sample.
1 parent ac25f72 commit 6f2ac2d

File tree

110 files changed

+6908
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+6908
-0
lines changed

Binding Dapper using CustomAdaptor/Grid_Dapper/.vs/Grid_Dapper/config/applicationhost.config

+1,011
Large diffs are not rendered by default.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
{
2+
"Version": 1,
3+
"WorkspaceRootPath": "D:\\angular\\typescript\\custom-js\\Grid_Dapper\\",
4+
"Documents": [
5+
{
6+
"AbsoluteMoniker": "D:0:0:{BD6E98FB-9DE2-4D39-8176-6A0BD9CD9C12}|Grid_Dapper.csproj|d:\\angular\\typescript\\custom-js\\grid_dapper\\wwwroot\\js\\index.js||{14D17961-FE51-464D-9111-C4AF11D7D99A}",
7+
"RelativeMoniker": "D:0:0:{BD6E98FB-9DE2-4D39-8176-6A0BD9CD9C12}|Grid_Dapper.csproj|solutionrelative:wwwroot\\js\\index.js||{14D17961-FE51-464D-9111-C4AF11D7D99A}"
8+
},
9+
{
10+
"AbsoluteMoniker": "D:0:0:{BD6E98FB-9DE2-4D39-8176-6A0BD9CD9C12}|Grid_Dapper.csproj|d:\\angular\\typescript\\custom-js\\grid_dapper\\wwwroot\\js\\customadaptor.js||{14D17961-FE51-464D-9111-C4AF11D7D99A}",
11+
"RelativeMoniker": "D:0:0:{BD6E98FB-9DE2-4D39-8176-6A0BD9CD9C12}|Grid_Dapper.csproj|solutionrelative:wwwroot\\js\\customadaptor.js||{14D17961-FE51-464D-9111-C4AF11D7D99A}"
12+
},
13+
{
14+
"AbsoluteMoniker": "D:0:0:{BD6E98FB-9DE2-4D39-8176-6A0BD9CD9C12}|Grid_Dapper.csproj|d:\\angular\\typescript\\custom-js\\grid_dapper\\wwwroot\\index.html||{40D31677-CBC0-4297-A9EF-89D907823A98}",
15+
"RelativeMoniker": "D:0:0:{BD6E98FB-9DE2-4D39-8176-6A0BD9CD9C12}|Grid_Dapper.csproj|solutionrelative:wwwroot\\index.html||{40D31677-CBC0-4297-A9EF-89D907823A98}"
16+
},
17+
{
18+
"AbsoluteMoniker": "D:0:0:{BD6E98FB-9DE2-4D39-8176-6A0BD9CD9C12}|Grid_Dapper.csproj|d:\\angular\\typescript\\custom-js\\grid_dapper\\controllers\\gridcontroller.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
19+
"RelativeMoniker": "D:0:0:{BD6E98FB-9DE2-4D39-8176-6A0BD9CD9C12}|Grid_Dapper.csproj|solutionrelative:controllers\\gridcontroller.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
20+
},
21+
{
22+
"AbsoluteMoniker": "D:0:0:{BD6E98FB-9DE2-4D39-8176-6A0BD9CD9C12}|Grid_Dapper.csproj|d:\\angular\\typescript\\custom-js\\grid_dapper\\program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
23+
"RelativeMoniker": "D:0:0:{BD6E98FB-9DE2-4D39-8176-6A0BD9CD9C12}|Grid_Dapper.csproj|solutionrelative:program.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
24+
},
25+
{
26+
"AbsoluteMoniker": "D:0:0:{BD6E98FB-9DE2-4D39-8176-6A0BD9CD9C12}|Grid_Dapper.csproj|d:\\angular\\typescript\\custom-js\\grid_dapper\\properties\\launchsettings.json||{90A6B3A7-C1A3-4009-A288-E2FF89E96FA0}",
27+
"RelativeMoniker": "D:0:0:{BD6E98FB-9DE2-4D39-8176-6A0BD9CD9C12}|Grid_Dapper.csproj|solutionrelative:properties\\launchsettings.json||{90A6B3A7-C1A3-4009-A288-E2FF89E96FA0}"
28+
}
29+
],
30+
"DocumentGroupContainers": [
31+
{
32+
"Orientation": 0,
33+
"VerticalTabListWidth": 256,
34+
"DocumentGroups": [
35+
{
36+
"DockedWidth": 200,
37+
"SelectedChildIndex": 0,
38+
"Children": [
39+
{
40+
"$type": "Document",
41+
"DocumentIndex": 0,
42+
"Title": "index.js",
43+
"DocumentMoniker": "D:\\angular\\typescript\\custom-js\\Grid_Dapper\\wwwroot\\js\\index.js",
44+
"RelativeDocumentMoniker": "wwwroot\\js\\index.js",
45+
"ToolTip": "D:\\angular\\typescript\\custom-js\\Grid_Dapper\\wwwroot\\js\\index.js",
46+
"RelativeToolTip": "wwwroot\\js\\index.js",
47+
"ViewState": "AQIAAAAAAAAAAAAAAAAAAAEAAAAAAAAA",
48+
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.001646|",
49+
"WhenOpened": "2025-03-24T14:02:40.678Z",
50+
"IsPinned": true,
51+
"EditorCaption": ""
52+
},
53+
{
54+
"$type": "Document",
55+
"DocumentIndex": 5,
56+
"Title": "launchSettings.json",
57+
"DocumentMoniker": "D:\\angular\\typescript\\custom-js\\Grid_Dapper\\Properties\\launchSettings.json",
58+
"RelativeDocumentMoniker": "Properties\\launchSettings.json",
59+
"ToolTip": "D:\\angular\\typescript\\custom-js\\Grid_Dapper\\Properties\\launchSettings.json",
60+
"RelativeToolTip": "Properties\\launchSettings.json",
61+
"ViewState": "AQIAAAYAAAAAAAAAAAAAABkAAAAIAAAA",
62+
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.001642|",
63+
"WhenOpened": "2025-03-24T14:05:38.561Z",
64+
"EditorCaption": ""
65+
},
66+
{
67+
"$type": "Document",
68+
"DocumentIndex": 4,
69+
"Title": "Program.cs",
70+
"DocumentMoniker": "D:\\angular\\typescript\\custom-js\\Grid_Dapper\\Program.cs",
71+
"RelativeDocumentMoniker": "Program.cs",
72+
"ToolTip": "D:\\angular\\typescript\\custom-js\\Grid_Dapper\\Program.cs",
73+
"RelativeToolTip": "Program.cs",
74+
"ViewState": "AQIAAAYAAAAAAAAAAAAAABQAAAAVAAAA",
75+
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
76+
"WhenOpened": "2025-03-24T14:13:06.767Z",
77+
"EditorCaption": ""
78+
},
79+
{
80+
"$type": "Document",
81+
"DocumentIndex": 1,
82+
"Title": "CustomAdaptor.js",
83+
"DocumentMoniker": "D:\\angular\\typescript\\custom-js\\Grid_Dapper\\wwwroot\\js\\CustomAdaptor.js",
84+
"RelativeDocumentMoniker": "wwwroot\\js\\CustomAdaptor.js",
85+
"ToolTip": "D:\\angular\\typescript\\custom-js\\Grid_Dapper\\wwwroot\\js\\CustomAdaptor.js",
86+
"RelativeToolTip": "wwwroot\\js\\CustomAdaptor.js",
87+
"ViewState": "AQIAAAAAAAAAAAAAAAAAAAEAAAArAAAA",
88+
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.001646|",
89+
"WhenOpened": "2025-03-24T14:07:40.709Z",
90+
"EditorCaption": ""
91+
},
92+
{
93+
"$type": "Document",
94+
"DocumentIndex": 3,
95+
"Title": "GridController.cs",
96+
"DocumentMoniker": "D:\\angular\\typescript\\custom-js\\Grid_Dapper\\Controllers\\GridController.cs",
97+
"RelativeDocumentMoniker": "Controllers\\GridController.cs",
98+
"ToolTip": "D:\\angular\\typescript\\custom-js\\Grid_Dapper\\Controllers\\GridController.cs",
99+
"RelativeToolTip": "Controllers\\GridController.cs",
100+
"ViewState": "AQIAAFcAAAAAAAAAAAAwwOEAAAAAAAAA",
101+
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
102+
"WhenOpened": "2025-03-24T14:03:38.928Z",
103+
"EditorCaption": ""
104+
},
105+
{
106+
"$type": "Document",
107+
"DocumentIndex": 2,
108+
"Title": "index.html",
109+
"DocumentMoniker": "D:\\angular\\typescript\\custom-js\\Grid_Dapper\\wwwroot\\index.html",
110+
"RelativeDocumentMoniker": "wwwroot\\index.html",
111+
"ToolTip": "D:\\angular\\typescript\\custom-js\\Grid_Dapper\\wwwroot\\index.html",
112+
"RelativeToolTip": "wwwroot\\index.html",
113+
"ViewState": "AQIAAAoAAAAAAAAAAAAQwB8AAAAHAAAA",
114+
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.001512|",
115+
"WhenOpened": "2025-03-24T14:02:08.039Z",
116+
"EditorCaption": ""
117+
}
118+
]
119+
}
120+
]
121+
}
122+
]
123+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Syncfusion.EJ2.Base;
3+
using System.ComponentModel.DataAnnotations;
4+
using System.Data;
5+
using Microsoft.Data.SqlClient;
6+
using Dapper;
7+
using System.Collections;
8+
9+
namespace Grid_Dapper.Controllers
10+
{
11+
[ApiController]
12+
public class GridController : ControllerBase
13+
{
14+
15+
string ConnectionString = @"<Enter a valid connection string>";
16+
17+
[HttpPost]
18+
[Route("api/[controller]")]
19+
public object Post([FromBody] DataManagerRequest DataManagerRequest)
20+
{
21+
// Retrieve data from the data source (e.g., database)
22+
IQueryable<Orders> DataSource = GetOrderData().AsQueryable();
23+
24+
QueryableOperation queryableOperation = new QueryableOperation(); // Initialize QueryableOperation instance
25+
26+
27+
// Handling Searching operation
28+
if (DataManagerRequest.Search != null && DataManagerRequest.Search.Count > 0)
29+
{
30+
DataSource = queryableOperation.PerformSearching(DataSource, DataManagerRequest.Search);
31+
}
32+
33+
// Handling filtering operation
34+
if (DataManagerRequest.Where != null && DataManagerRequest.Where.Count > 0)
35+
{
36+
foreach (var condition in DataManagerRequest.Where)
37+
{
38+
foreach (var predicate in condition.predicates)
39+
{
40+
DataSource = queryableOperation.PerformFiltering(DataSource, DataManagerRequest.Where, predicate.Operator);
41+
}
42+
}
43+
}
44+
45+
// Handling Sorting operation.
46+
if (DataManagerRequest.Sorted != null && DataManagerRequest.Sorted.Count > 0)
47+
{
48+
DataSource = queryableOperation.PerformSorting(DataSource, DataManagerRequest.Sorted);
49+
}
50+
// Handle aggregation
51+
List<string> str = new List<string>();
52+
if (DataManagerRequest.Aggregates != null)
53+
{
54+
for (var i = 0; i < DataManagerRequest.Aggregates.Count; i++)
55+
{
56+
str.Add(DataManagerRequest.Aggregates[i].Field);
57+
}
58+
}
59+
60+
// Assuming PerformSelect is the method that handles the aggregation logic
61+
IEnumerable aggregate = queryableOperation.PerformSelect(DataSource, str);
62+
63+
// Get the total count of records.
64+
int totalRecordsCount = DataSource.Count();
65+
66+
// Handling paging operation.
67+
if (DataManagerRequest.Skip != 0)
68+
{
69+
70+
DataSource = queryableOperation.PerformSkip(DataSource, DataManagerRequest.Skip);
71+
}
72+
if (DataManagerRequest.Take != 0)
73+
{
74+
DataSource = queryableOperation.PerformTake(DataSource, DataManagerRequest.Take);
75+
}
76+
77+
// Return data based on the request.
78+
return new { result = DataSource, count = totalRecordsCount, aggregate = aggregate };
79+
}
80+
81+
[HttpGet]
82+
[Route("api/[controller]")]
83+
public List<Orders> GetOrderData()
84+
{
85+
string Query = "SELECT * FROM dbo.Orders ORDER BY OrderID;";
86+
//Create SQL Connection.
87+
using (IDbConnection Connection = new SqlConnection(ConnectionString))
88+
{
89+
Connection.Open();
90+
// Dapper automatically handles mapping to your Order class.
91+
List<Orders> orders = Connection.Query<Orders>(Query).ToList();
92+
return orders;
93+
}
94+
}
95+
96+
/// <summary>
97+
/// Inserts a new data item into the data collection.
98+
/// </summary>
99+
/// <param name="newRecord">It contains the new record detail which is need to be inserted.</param>
100+
/// <returns>Returns void</returns>
101+
[HttpPost]
102+
[Route("api/[controller]/Insert")]
103+
public void Insert([FromBody] CRUDModel<Orders> value)
104+
{
105+
//Create query to insert the specific into the database by accessing its properties
106+
string Query = "INSERT INTO Orders(CustomerID, Freight, ShipCity, EmployeeID) VALUES(@CustomerID, @Freight, @ShipCity, @EmployeeID)";
107+
using (IDbConnection Connection = new SqlConnection(ConnectionString))
108+
{
109+
Connection.Open();
110+
//Execute this code to reflect the changes into the database
111+
Connection.Execute(Query, value.value);
112+
}
113+
114+
}
115+
116+
/// <summary>
117+
/// Update a existing data item from the data collection.
118+
/// </summary>
119+
/// <param name="Order">It contains the updated record detail which is need to be updated.</param>
120+
/// <returns>Returns void</returns>
121+
[HttpPost]
122+
[Route("api/[controller]/Update")]
123+
public void Update([FromBody] CRUDModel<Orders> value)
124+
{
125+
//Create query to update the changes into the database by accessing its properties
126+
string Query = "UPDATE Orders SET CustomerID = @CustomerID, Freight = @Freight, ShipCity = @ShipCity, EmployeeID = @EmployeeID WHERE OrderID = @OrderID";
127+
using (IDbConnection Connection = new SqlConnection(ConnectionString))
128+
{
129+
Connection.Open();
130+
//Execute this code to reflect the changes into the database
131+
Connection.Execute(Query, value.value);
132+
}
133+
}
134+
135+
/// <summary>
136+
/// Remove a specific data item from the data collection.
137+
/// </summary>
138+
/// <param name="value">It contains the specific record detail which is need to be removed.</param>
139+
/// <return>Returns void</return>
140+
[HttpPost]
141+
[Route("api/[controller]/Remove")]
142+
public void Remove([FromBody] CRUDModel<Orders> value)
143+
{
144+
//Create query to remove the specific from database by passing the primary key column value.
145+
string Query = "DELETE FROM Orders WHERE OrderID = @OrderID";
146+
using (IDbConnection Connection = new SqlConnection(ConnectionString))
147+
{
148+
Connection.Open();
149+
int orderID = Convert.ToInt32(value.key.ToString());
150+
//Execute this code to reflect the changes into the database
151+
Connection.Execute(Query, new { OrderID = orderID });
152+
}
153+
}
154+
155+
156+
157+
/// <summary>
158+
/// The code for handling CRUD operation when enbaling batch editing
159+
/// </summary>
160+
/// <param name="batchmodel"></param>
161+
/// <returns></returns>
162+
163+
[HttpPost]
164+
[Route("api/[controller]/BatchUpdate")]
165+
public IActionResult BatchUpdate([FromBody] CRUDModel<Orders> value)
166+
{
167+
//TODO: Enter the connectionstring of database
168+
if (value.changed != null && value.changed.Count > 0)
169+
{
170+
foreach (var Record in (IEnumerable<Orders>)value.changed)
171+
{
172+
//Create query to update the changes into the database by accessing its properties
173+
string Query = "UPDATE Orders SET CustomerID = @CustomerID, Freight = @Freight, ShipCity = @ShipCity, EmployeeID = @EmployeeID WHERE OrderID = @OrderID";
174+
using (IDbConnection Connection = new SqlConnection(ConnectionString))
175+
{
176+
Connection.Open();
177+
//Execute this code to reflect the changes into the database
178+
Connection.Execute(Query, Record);
179+
}
180+
}
181+
182+
}
183+
if (value.added != null && value.added.Count > 0)
184+
{
185+
foreach (var Record in (IEnumerable<Orders>)value.added)
186+
{
187+
//Create query to insert the specific into the database by accessing its properties
188+
string Query = "INSERT INTO Orders (CustomerID, Freight, ShipCity, EmployeeID) VALUES (@CustomerID, @Freight, @ShipCity, @EmployeeID)";
189+
using (IDbConnection Connection = new SqlConnection(ConnectionString))
190+
{
191+
Connection.Open();
192+
//Execute this code to reflect the changes into the database
193+
Connection.Execute(Query, Record);
194+
}
195+
}
196+
}
197+
if (value.deleted != null && value.deleted.Count > 0)
198+
{
199+
foreach (var Record in (IEnumerable<Orders>)value.deleted)
200+
{
201+
//Create query to remove the specific from database by passing the primary key column value.
202+
string Query = "DELETE FROM Orders WHERE OrderID = @OrderID";
203+
using (IDbConnection Connection = new SqlConnection(ConnectionString))
204+
{
205+
Connection.Open();
206+
//Execute this code to reflect the changes into the database
207+
Connection.Execute(Query, new { OrderID = Record.OrderID });
208+
}
209+
}
210+
}
211+
return new JsonResult(value);
212+
213+
}
214+
215+
216+
217+
218+
public class CRUDModel<T> where T : class
219+
{
220+
221+
public string? action { get; set; }
222+
223+
public string? keyColumn { get; set; }
224+
225+
public object? key { get; set; }
226+
227+
public T? value { get; set; }
228+
229+
public List<T>? added { get; set; }
230+
231+
public List<T>? changed { get; set; }
232+
233+
public List<T>? deleted { get; set; }
234+
235+
public IDictionary<string, object>? @params { get; set; }
236+
237+
}
238+
public class Orders
239+
{
240+
[Key]
241+
public int? OrderID { get; set; }
242+
public string? CustomerID { get; set; }
243+
public int? EmployeeID { get; set; }
244+
public decimal? Freight { get; set; }
245+
public string? ShipCity { get; set; }
246+
}
247+
248+
}
249+
}

0 commit comments

Comments
 (0)