@@ -12,7 +12,7 @@ namespace Grid_Dapper.Controllers
1212 public class GridController : ControllerBase
1313 {
1414
15- string ConnectionString = @"<Enter a valid connection string>" ;
15+ string ConnectionString = @"<Enter a valid connection string>" ;
1616
1717 /// <summary>
1818 /// Processes the DataManager request to perform searching, filtering, sorting, and paging operations.
@@ -23,64 +23,57 @@ public class GridController : ControllerBase
2323 [ Route ( "api/[controller]" ) ]
2424 public object Post ( [ FromBody ] DataManagerRequest DataManagerRequest )
2525 {
26- // Retrieve data from the data source (e.g., database)
26+ // Retrieve data from the data source (e.g., database).
2727 IQueryable < Orders > DataSource = GetOrderData ( ) . AsQueryable ( ) ;
2828
29- QueryableOperation queryableOperation = new QueryableOperation ( ) ; // Initialize QueryableOperation instance
29+ // Initialize QueryableOperation instance.
30+ QueryableOperation queryableOperation = new QueryableOperation ( ) ;
3031
31-
32- // Handling Searching operation
32+ // Handling searching operation.
3333 if ( DataManagerRequest . Search != null && DataManagerRequest . Search . Count > 0 )
3434 {
3535 DataSource = queryableOperation . PerformSearching ( DataSource , DataManagerRequest . Search ) ;
36+ //Add custom logic here if needed and remove above method.
3637 }
3738
38- // Handling filtering operation
39+ // Handling filtering operation.
3940 if ( DataManagerRequest . Where != null && DataManagerRequest . Where . Count > 0 )
4041 {
41- foreach ( var condition in DataManagerRequest . Where )
42+ foreach ( WhereFilter condition in DataManagerRequest . Where )
4243 {
43- foreach ( var predicate in condition . predicates )
44+ foreach ( WhereFilter predicate in condition . predicates )
4445 {
4546 DataSource = queryableOperation . PerformFiltering ( DataSource , DataManagerRequest . Where , predicate . Operator ) ;
47+ //Add custom logic here if needed and remove above method.
4648 }
4749 }
4850 }
4951
50- // Handling Sorting operation.
52+ // Handling sorting operation.
5153 if ( DataManagerRequest . Sorted != null && DataManagerRequest . Sorted . Count > 0 )
5254 {
5355 DataSource = queryableOperation . PerformSorting ( DataSource , DataManagerRequest . Sorted ) ;
54- }
55- // Handle aggregation
56- List < string > str = new List < string > ( ) ;
57- if ( DataManagerRequest . Aggregates != null )
58- {
59- for ( var i = 0 ; i < DataManagerRequest . Aggregates . Count ; i ++ )
60- {
61- str . Add ( DataManagerRequest . Aggregates [ i ] . Field ) ;
62- }
56+ //Add custom logic here if needed and remove above method.
6357 }
6458
65- // Assuming PerformSelect is the method that handles the aggregation logic
66- IEnumerable aggregate = queryableOperation . PerformSelect ( DataSource , str ) ;
6759
6860 // Get the total count of records.
6961 int totalRecordsCount = DataSource . Count ( ) ;
7062
7163 // Handling paging operation.
7264 if ( DataManagerRequest . Skip != 0 )
7365 {
74-
7566 DataSource = queryableOperation . PerformSkip ( DataSource , DataManagerRequest . Skip ) ;
67+ //Add custom logic here if needed and remove above method.
7668 }
7769 if ( DataManagerRequest . Take != 0 )
7870 {
7971 DataSource = queryableOperation . PerformTake ( DataSource , DataManagerRequest . Take ) ;
72+ //Add custom logic here if needed and remove above method.
8073 }
8174
8275 // Return data based on the request.
83- return new { result = DataSource , count = totalRecordsCount , aggregate = aggregate } ;
76+ return new { result = DataSource , count = totalRecordsCount } ;
8477 }
8578
8679 [ HttpGet ]
@@ -101,120 +94,139 @@ public List<Orders> GetOrderData()
10194 /// <summary>
10295 /// Inserts a new data item into the data collection.
10396 /// </summary>
104- /// <param name="newRecord ">It contains the new record detail which is need to be inserted.</param>
105- /// <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>
10699 [ HttpPost ]
107100 [ Route ( "api/[controller]/Insert" ) ]
108101 public void Insert ( [ FromBody ] CRUDModel < Orders > value )
109102 {
110- //Create query to insert the specific into the database by accessing its properties
111- 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.
112107 using ( IDbConnection Connection = new SqlConnection ( ConnectionString ) )
113108 {
114109 Connection . Open ( ) ;
115- //Execute this code to reflect the changes into the database
116- Connection . Execute ( Query , value . value ) ;
110+ //Execute this code to reflect the changes into the database.
111+ Connection . Execute ( queryStr , value . value ) ;
117112 }
118113
114+ //Add custom logic here if needed and remove above method.
119115 }
120116
121117 /// <summary>
122118 /// Update a existing data item from the data collection.
123119 /// </summary>
124- /// <param name="Order ">It contains the updated record detail which is need to be updated.</param>
125- /// <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>
126122 [ HttpPost ]
127123 [ Route ( "api/[controller]/Update" ) ]
128124 public void Update ( [ FromBody ] CRUDModel < Orders > value )
129125 {
130- //Create query to update the changes into the database by accessing its properties
131- 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.
132130 using ( IDbConnection Connection = new SqlConnection ( ConnectionString ) )
133131 {
134132 Connection . Open ( ) ;
135- //Execute this code to reflect the changes into the database
136- Connection . Execute ( Query , value . value ) ;
133+ //Execute this code to reflect the changes into the database.
134+ Connection . Execute ( queryStr , value . value ) ;
137135 }
136+
137+ //Add custom logic here if needed and remove above method.
138138 }
139139
140140 /// <summary>
141141 /// Remove a specific data item from the data collection.
142142 /// </summary>
143143 /// <param name="value">It contains the specific record detail which is need to be removed.</param>
144- /// <return>Returns void</return>
144+ /// <return>Returns void. </return>
145145 [ HttpPost ]
146146 [ Route ( "api/[controller]/Remove" ) ]
147147 public void Remove ( [ FromBody ] CRUDModel < Orders > value )
148148 {
149149 //Create query to remove the specific from database by passing the primary key column value.
150- string Query = "DELETE FROM Orders WHERE OrderID = @OrderID" ;
150+ string queryStr = "DELETE FROM Orders WHERE OrderID = @OrderID" ;
151+
152+ //Create SQL connection.
151153 using ( IDbConnection Connection = new SqlConnection ( ConnectionString ) )
152154 {
153155 Connection . Open ( ) ;
154156 int orderID = Convert . ToInt32 ( value . key . ToString ( ) ) ;
155- //Execute this code to reflect the changes into the database
156- Connection . Execute ( Query , new { OrderID = orderID } ) ;
157+ //Execute this code to reflect the changes into the database.
158+ Connection . Execute ( queryStr , new { OrderID = orderID } ) ;
157159 }
160+
161+ //Add custom logic here if needed and remove above method.
158162 }
159163
160164
161165
162166 /// <summary>
163- /// 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.
164168 /// </summary>
165- /// <param name="batchmodel"></param>
166- /// <returns></returns>
167-
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>
168171 [ HttpPost ]
169172 [ Route ( "api/[controller]/BatchUpdate" ) ]
170173 public IActionResult BatchUpdate ( [ FromBody ] CRUDModel < Orders > value )
171174 {
172- //TODO: Enter the connectionstring of database
173175 if ( value . changed != null && value . changed . Count > 0 )
174176 {
175- foreach ( var Record in ( IEnumerable < Orders > ) value . changed )
177+ foreach ( Orders Record in ( IEnumerable < Orders > ) value . changed )
176178 {
177- //Create query to update the changes into the database by accessing its properties
178- string Query = "UPDATE Orders SET CustomerID = @CustomerID, Freight = @Freight, ShipCity = @ShipCity, EmployeeID = @EmployeeID WHERE OrderID = @OrderID" ;
179- using ( IDbConnection Connection = new SqlConnection ( ConnectionString ) )
180- {
181- Connection . Open ( ) ;
182- //Execute this code to reflect the changes into the database
183- Connection . Execute ( Query , Record ) ;
184- }
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 ) ;
185188 }
186189
190+ //Add custom logic here if needed and remove above method.
191+ }
187192 }
188193 if ( value . added != null && value . added . Count > 0 )
189194 {
190- foreach ( var Record in ( IEnumerable < Orders > ) value . added )
195+ foreach ( Orders Record in ( IEnumerable < Orders > ) value . added )
191196 {
192- //Create query to insert the specific into the database by accessing its properties
193- string Query = "INSERT INTO Orders (CustomerID, Freight, ShipCity, EmployeeID) VALUES (@CustomerID, @Freight, @ShipCity, @EmployeeID)" ;
194- using ( IDbConnection Connection = new SqlConnection ( ConnectionString ) )
195- {
196- Connection . Open ( ) ;
197- //Execute this code to reflect the changes into the database
198- Connection . Execute ( Query , Record ) ;
199- }
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.
200209 }
201210 }
202211 if ( value . deleted != null && value . deleted . Count > 0 )
203212 {
204- foreach ( var Record in ( IEnumerable < Orders > ) value . deleted )
213+ foreach ( Orders Record in ( IEnumerable < Orders > ) value . deleted )
205214 {
206215 //Create query to remove the specific from database by passing the primary key column value.
207- string Query = "DELETE FROM Orders WHERE OrderID = @OrderID" ;
216+ string queryStr = "DELETE FROM Orders WHERE OrderID = @OrderID" ;
217+
218+ //Create SQL connection.
208219 using ( IDbConnection Connection = new SqlConnection ( ConnectionString ) )
209220 {
210221 Connection . Open ( ) ;
211- //Execute this code to reflect the changes into the database
212- 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 } ) ;
213224 }
225+
226+ //Add custom logic here if needed and remove above method.
214227 }
215228 }
216- return new JsonResult ( value ) ;
217-
229+ return new JsonResult ( value ) ;
218230 }
219231
220232
@@ -249,6 +261,6 @@ public class Orders
249261 public decimal ? Freight { get ; set ; }
250262 public string ? ShipCity { get ; set ; }
251263 }
252-
253- }
264+
265+ }
254266}
0 commit comments