11using Microsoft . AspNetCore . Http ;
22using Microsoft . AspNetCore . Mvc ;
3- using Syncfusion . EJ2 . Base ;
43using UrlAdaptor . Server . Models ;
5-
4+ using Syncfusion . EJ2 . Base ;
65
76namespace 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+ }
0 commit comments