@@ -13,69 +13,67 @@ public class GridController : ControllerBase
1313 {
1414
1515 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>
1722 [ HttpPost ]
1823 [ Route ( "api/[controller]" ) ]
1924 public object Post ( [ FromBody ] DataManagerRequest DataManagerRequest )
2025 {
21- // Retrieve data from the data source (e.g., database)
26+ // Retrieve data from the data source (e.g., database).
2227 IQueryable < Orders > DataSource = GetOrderData ( ) . AsQueryable ( ) ;
2328
24- QueryableOperation queryableOperation = new QueryableOperation ( ) ; // Initialize QueryableOperation instance
25-
29+ // Initialize QueryableOperation instance.
30+ QueryableOperation queryableOperation = new QueryableOperation ( ) ;
2631
27- // Handling Searching operation
32+ // Handling searching operation.
2833 if ( DataManagerRequest . Search != null && DataManagerRequest . Search . Count > 0 )
2934 {
3035 DataSource = queryableOperation . PerformSearching ( DataSource , DataManagerRequest . Search ) ;
36+ //Add custom logic here if needed and remove above method.
3137 }
3238
33- // Handling filtering operation
39+ // Handling filtering operation.
3440 if ( DataManagerRequest . Where != null && DataManagerRequest . Where . Count > 0 )
3541 {
36- foreach ( var condition in DataManagerRequest . Where )
42+ foreach ( WhereFilter condition in DataManagerRequest . Where )
3743 {
38- foreach ( var predicate in condition . predicates )
44+ foreach ( WhereFilter predicate in condition . predicates )
3945 {
4046 DataSource = queryableOperation . PerformFiltering ( DataSource , DataManagerRequest . Where , predicate . Operator ) ;
47+ //Add custom logic here if needed and remove above method.
4148 }
4249 }
4350 }
4451
45- // Handling Sorting operation.
52+ // Handling sorting operation.
4653 if ( DataManagerRequest . Sorted != null && DataManagerRequest . Sorted . Count > 0 )
4754 {
4855 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.
5857 }
5958
60- // Assuming PerformSelect is the method that handles the aggregation logic
61- IEnumerable aggregate = queryableOperation . PerformSelect ( DataSource , str ) ;
6259
6360 // Get the total count of records.
6461 int totalRecordsCount = DataSource . Count ( ) ;
6562
6663 // Handling paging operation.
6764 if ( DataManagerRequest . Skip != 0 )
6865 {
69-
7066 DataSource = queryableOperation . PerformSkip ( DataSource , DataManagerRequest . Skip ) ;
67+ //Add custom logic here if needed and remove above method.
7168 }
7269 if ( DataManagerRequest . Take != 0 )
7370 {
7471 DataSource = queryableOperation . PerformTake ( DataSource , DataManagerRequest . Take ) ;
72+ //Add custom logic here if needed and remove above method.
7573 }
7674
7775 // Return data based on the request.
78- return new { result = DataSource , count = totalRecordsCount , aggregate = aggregate } ;
76+ return new { result = DataSource , count = totalRecordsCount } ;
7977 }
8078
8179 [ HttpGet ]
@@ -96,120 +94,139 @@ public List<Orders> GetOrderData()
9694 /// <summary>
9795 /// Inserts a new data item into the data collection.
9896 /// </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>
10199 [ HttpPost ]
102100 [ Route ( "api/[controller]/Insert" ) ]
103101 public void Insert ( [ FromBody ] CRUDModel < Orders > value )
104102 {
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.
107107 using ( IDbConnection Connection = new SqlConnection ( ConnectionString ) )
108108 {
109109 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 ) ;
112112 }
113113
114+ //Add custom logic here if needed and remove above method.
114115 }
115116
116117 /// <summary>
117118 /// Update a existing data item from the data collection.
118119 /// </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>
121122 [ HttpPost ]
122123 [ Route ( "api/[controller]/Update" ) ]
123124 public void Update ( [ FromBody ] CRUDModel < Orders > value )
124125 {
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.
127130 using ( IDbConnection Connection = new SqlConnection ( ConnectionString ) )
128131 {
129132 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 ) ;
132135 }
136+
137+ //Add custom logic here if needed and remove above method.
133138 }
134139
135140 /// <summary>
136141 /// Remove a specific data item from the data collection.
137142 /// </summary>
138143 /// <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>
140145 [ HttpPost ]
141146 [ Route ( "api/[controller]/Remove" ) ]
142147 public void Remove ( [ FromBody ] CRUDModel < Orders > value )
143148 {
144149 //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.
146153 using ( IDbConnection Connection = new SqlConnection ( ConnectionString ) )
147154 {
148155 Connection . Open ( ) ;
149156 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 } ) ;
152159 }
160+
161+ //Add custom logic here if needed and remove above method.
153162 }
154163
155164
156165
157166 /// <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.
159168 /// </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>
163171 [ HttpPost ]
164172 [ Route ( "api/[controller]/BatchUpdate" ) ]
165173 public IActionResult BatchUpdate ( [ FromBody ] CRUDModel < Orders > value )
166174 {
167- //TODO: Enter the connectionstring of database
168175 if ( value . changed != null && value . changed . Count > 0 )
169176 {
170- foreach ( var Record in ( IEnumerable < Orders > ) value . changed )
177+ foreach ( Orders Record in ( IEnumerable < Orders > ) value . changed )
171178 {
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 ) ;
180188 }
181189
190+ //Add custom logic here if needed and remove above method.
191+ }
182192 }
183193 if ( value . added != null && value . added . Count > 0 )
184194 {
185- foreach ( var Record in ( IEnumerable < Orders > ) value . added )
195+ foreach ( Orders Record in ( IEnumerable < Orders > ) value . added )
186196 {
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.
195209 }
196210 }
197211 if ( value . deleted != null && value . deleted . Count > 0 )
198212 {
199- foreach ( var Record in ( IEnumerable < Orders > ) value . deleted )
213+ foreach ( Orders Record in ( IEnumerable < Orders > ) value . deleted )
200214 {
201215 //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.
203219 using ( IDbConnection Connection = new SqlConnection ( ConnectionString ) )
204220 {
205221 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 } ) ;
208224 }
225+
226+ //Add custom logic here if needed and remove above method.
209227 }
210228 }
211- return new JsonResult ( value ) ;
212-
229+ return new JsonResult ( value ) ;
213230 }
214231
215232
0 commit comments