@@ -13,69 +13,67 @@ public class GridController : ControllerBase
13
13
{
14
14
15
15
string ConnectionString = @"<Enter a valid connection string>" ;
16
-
16
+
17
+ /// <summary>
18
+ /// Processes the DataManager request to perform searching, filtering, sorting, and paging operations.
19
+ /// </summary>
20
+ /// <param name="DataManagerRequest">Contains the details of the data operation requested.</param>
21
+ /// <returns>Returns a JSON object with the filtered, sorted, and paginated data along with the total record count.</returns>
17
22
[ HttpPost ]
18
23
[ Route ( "api/[controller]" ) ]
19
24
public object Post ( [ FromBody ] DataManagerRequest DataManagerRequest )
20
25
{
21
- // Retrieve data from the data source (e.g., database)
26
+ // Retrieve data from the data source (e.g., database).
22
27
IQueryable < Orders > DataSource = GetOrderData ( ) . AsQueryable ( ) ;
23
28
24
- QueryableOperation queryableOperation = new QueryableOperation ( ) ; // Initialize QueryableOperation instance
25
-
29
+ // Initialize QueryableOperation instance.
30
+ QueryableOperation queryableOperation = new QueryableOperation ( ) ;
26
31
27
- // Handling Searching operation
32
+ // Handling searching operation.
28
33
if ( DataManagerRequest . Search != null && DataManagerRequest . Search . Count > 0 )
29
34
{
30
35
DataSource = queryableOperation . PerformSearching ( DataSource , DataManagerRequest . Search ) ;
36
+ //Add custom logic here if needed and remove above method.
31
37
}
32
38
33
- // Handling filtering operation
39
+ // Handling filtering operation.
34
40
if ( DataManagerRequest . Where != null && DataManagerRequest . Where . Count > 0 )
35
41
{
36
- foreach ( var condition in DataManagerRequest . Where )
42
+ foreach ( WhereFilter condition in DataManagerRequest . Where )
37
43
{
38
- foreach ( var predicate in condition . predicates )
44
+ foreach ( WhereFilter predicate in condition . predicates )
39
45
{
40
46
DataSource = queryableOperation . PerformFiltering ( DataSource , DataManagerRequest . Where , predicate . Operator ) ;
47
+ //Add custom logic here if needed and remove above method.
41
48
}
42
49
}
43
50
}
44
51
45
- // Handling Sorting operation.
52
+ // Handling sorting operation.
46
53
if ( DataManagerRequest . Sorted != null && DataManagerRequest . Sorted . Count > 0 )
47
54
{
48
55
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
- }
56
+ //Add custom logic here if needed and remove above method.
58
57
}
59
58
60
- // Assuming PerformSelect is the method that handles the aggregation logic
61
- IEnumerable aggregate = queryableOperation . PerformSelect ( DataSource , str ) ;
62
59
63
60
// Get the total count of records.
64
61
int totalRecordsCount = DataSource . Count ( ) ;
65
62
66
63
// Handling paging operation.
67
64
if ( DataManagerRequest . Skip != 0 )
68
65
{
69
-
70
66
DataSource = queryableOperation . PerformSkip ( DataSource , DataManagerRequest . Skip ) ;
67
+ //Add custom logic here if needed and remove above method.
71
68
}
72
69
if ( DataManagerRequest . Take != 0 )
73
70
{
74
71
DataSource = queryableOperation . PerformTake ( DataSource , DataManagerRequest . Take ) ;
72
+ //Add custom logic here if needed and remove above method.
75
73
}
76
74
77
75
// Return data based on the request.
78
- return new { result = DataSource , count = totalRecordsCount , aggregate = aggregate } ;
76
+ return new { result = DataSource , count = totalRecordsCount } ;
79
77
}
80
78
81
79
[ HttpGet ]
@@ -96,120 +94,139 @@ public List<Orders> GetOrderData()
96
94
/// <summary>
97
95
/// Inserts a new data item into the data collection.
98
96
/// </summary>
99
- /// <param name="newRecord ">It contains the new record detail which is need to be inserted.</param>
100
- /// <returns>Returns void</returns>
97
+ /// <param name="value ">It contains the new record detail which is need to be inserted.</param>
98
+ /// <returns>Returns void. </returns>
101
99
[ HttpPost ]
102
100
[ Route ( "api/[controller]/Insert" ) ]
103
101
public void Insert ( [ FromBody ] CRUDModel < Orders > value )
104
102
{
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)" ;
103
+ //Create query to insert the specific into the database by accessing its properties.
104
+ string queryStr = "INSERT INTO Orders(CustomerID, Freight, ShipCity, EmployeeID) VALUES(@CustomerID, @Freight, @ShipCity, @EmployeeID)" ;
105
+
106
+ //Create SQL connection.
107
107
using ( IDbConnection Connection = new SqlConnection ( ConnectionString ) )
108
108
{
109
109
Connection . Open ( ) ;
110
- //Execute this code to reflect the changes into the database
111
- Connection . Execute ( Query , value . value ) ;
110
+ //Execute this code to reflect the changes into the database.
111
+ Connection . Execute ( queryStr , value . value ) ;
112
112
}
113
113
114
+ //Add custom logic here if needed and remove above method.
114
115
}
115
116
116
117
/// <summary>
117
118
/// Update a existing data item from the data collection.
118
119
/// </summary>
119
- /// <param name="Order ">It contains the updated record detail which is need to be updated.</param>
120
- /// <returns>Returns void</returns>
120
+ /// <param name="value ">It contains the updated record detail which is need to be updated.</param>
121
+ /// <returns>Returns void. </returns>
121
122
[ HttpPost ]
122
123
[ Route ( "api/[controller]/Update" ) ]
123
124
public void Update ( [ FromBody ] CRUDModel < Orders > value )
124
125
{
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" ;
126
+ //Create query to update the changes into the database by accessing its properties.
127
+ string queryStr = "UPDATE Orders SET CustomerID = @CustomerID, Freight = @Freight, ShipCity = @ShipCity, EmployeeID = @EmployeeID WHERE OrderID = @OrderID" ;
128
+
129
+ //Create SQL connection.
127
130
using ( IDbConnection Connection = new SqlConnection ( ConnectionString ) )
128
131
{
129
132
Connection . Open ( ) ;
130
- //Execute this code to reflect the changes into the database
131
- Connection . Execute ( Query , value . value ) ;
133
+ //Execute this code to reflect the changes into the database.
134
+ Connection . Execute ( queryStr , value . value ) ;
132
135
}
136
+
137
+ //Add custom logic here if needed and remove above method.
133
138
}
134
139
135
140
/// <summary>
136
141
/// Remove a specific data item from the data collection.
137
142
/// </summary>
138
143
/// <param name="value">It contains the specific record detail which is need to be removed.</param>
139
- /// <return>Returns void</return>
144
+ /// <return>Returns void. </return>
140
145
[ HttpPost ]
141
146
[ Route ( "api/[controller]/Remove" ) ]
142
147
public void Remove ( [ FromBody ] CRUDModel < Orders > value )
143
148
{
144
149
//Create query to remove the specific from database by passing the primary key column value.
145
- string Query = "DELETE FROM Orders WHERE OrderID = @OrderID" ;
150
+ string queryStr = "DELETE FROM Orders WHERE OrderID = @OrderID" ;
151
+
152
+ //Create SQL connection.
146
153
using ( IDbConnection Connection = new SqlConnection ( ConnectionString ) )
147
154
{
148
155
Connection . Open ( ) ;
149
156
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 } ) ;
157
+ //Execute this code to reflect the changes into the database.
158
+ Connection . Execute ( queryStr , new { OrderID = orderID } ) ;
152
159
}
160
+
161
+ //Add custom logic here if needed and remove above method.
153
162
}
154
163
155
164
156
165
157
166
/// <summary>
158
- /// The code for handling CRUD operation when enbaling batch editing
167
+ /// Batch update (Insert, Update, and Delete) a collection of data items from the data collection.
159
168
/// </summary>
160
- /// <param name="batchmodel"></param>
161
- /// <returns></returns>
162
-
169
+ /// <param name="value">The set of information along with details about the CRUD actions to be executed from the database.</param>
170
+ /// <returns>Returns void.</returns>
163
171
[ HttpPost ]
164
172
[ Route ( "api/[controller]/BatchUpdate" ) ]
165
173
public IActionResult BatchUpdate ( [ FromBody ] CRUDModel < Orders > value )
166
174
{
167
- //TODO: Enter the connectionstring of database
168
175
if ( value . changed != null && value . changed . Count > 0 )
169
176
{
170
- foreach ( var Record in ( IEnumerable < Orders > ) value . changed )
177
+ foreach ( Orders Record in ( IEnumerable < Orders > ) value . changed )
171
178
{
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
- }
179
+ //Create query to update the changes into the database by accessing its properties.
180
+ string queryStr = "UPDATE Orders SET CustomerID = @CustomerID, Freight = @Freight, ShipCity = @ShipCity, EmployeeID = @EmployeeID WHERE OrderID = @OrderID" ;
181
+
182
+ //Create SQL connection.
183
+ using ( IDbConnection Connection = new SqlConnection ( ConnectionString ) )
184
+ {
185
+ Connection . Open ( ) ;
186
+ //Execute this code to reflect the changes into the database.
187
+ Connection . Execute ( queryStr , Record ) ;
180
188
}
181
189
190
+ //Add custom logic here if needed and remove above method.
191
+ }
182
192
}
183
193
if ( value . added != null && value . added . Count > 0 )
184
194
{
185
- foreach ( var Record in ( IEnumerable < Orders > ) value . added )
195
+ foreach ( Orders Record in ( IEnumerable < Orders > ) value . added )
186
196
{
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
- }
197
+ //Create query to insert the specific into the database by accessing its properties.
198
+ string queryStr = "INSERT INTO Orders (CustomerID, Freight, ShipCity, EmployeeID) VALUES (@CustomerID, @Freight, @ShipCity, @EmployeeID)" ;
199
+
200
+ //Create SQL connection.
201
+ using ( IDbConnection Connection = new SqlConnection ( ConnectionString ) )
202
+ {
203
+ Connection . Open ( ) ;
204
+ //Execute this code to reflect the changes into the database.
205
+ Connection . Execute ( queryStr , Record ) ;
206
+ }
207
+
208
+ //Add custom logic here if needed and remove above method.
195
209
}
196
210
}
197
211
if ( value . deleted != null && value . deleted . Count > 0 )
198
212
{
199
- foreach ( var Record in ( IEnumerable < Orders > ) value . deleted )
213
+ foreach ( Orders Record in ( IEnumerable < Orders > ) value . deleted )
200
214
{
201
215
//Create query to remove the specific from database by passing the primary key column value.
202
- string Query = "DELETE FROM Orders WHERE OrderID = @OrderID" ;
216
+ string queryStr = "DELETE FROM Orders WHERE OrderID = @OrderID" ;
217
+
218
+ //Create SQL connection.
203
219
using ( IDbConnection Connection = new SqlConnection ( ConnectionString ) )
204
220
{
205
221
Connection . Open ( ) ;
206
- //Execute this code to reflect the changes into the database
207
- Connection . Execute ( Query , new { OrderID = Record . OrderID } ) ;
222
+ //Execute this code to reflect the changes into the database.
223
+ Connection . Execute ( queryStr , new { OrderID = Record . OrderID } ) ;
208
224
}
225
+
226
+ //Add custom logic here if needed and remove above method.
209
227
}
210
228
}
211
- return new JsonResult ( value ) ;
212
-
229
+ return new JsonResult ( value ) ;
213
230
}
214
231
215
232
0 commit comments