|
67 | 67 | public override async Task<object> ReadAsync(DataManagerRequest DataManagerRequest, string Key = null) |
68 | 68 | { |
69 | 69 | IEnumerable<Order> DataSource = await OrderService.GetOrdersAsync(); |
70 | | - // Handling Searching in Custom Adaptor. |
| 70 | + // Handling Searching in CustomAdaptor. |
71 | 71 | if (DataManagerRequest.Search != null && DataManagerRequest.Search.Count > 0) |
72 | 72 | { |
73 | 73 | // Searching |
74 | 74 | DataSource = DataOperations.PerformSearching(DataSource, DataManagerRequest.Search); |
75 | 75 | } |
76 | | - // Handling Filtering in Custom Adaptor. |
| 76 | + // Handling Filtering in CustomAdaptor. |
77 | 77 | if (DataManagerRequest.Where != null && DataManagerRequest.Where.Count > 0) |
78 | 78 | { |
79 | 79 | // Filtering |
80 | 80 | DataSource = DataOperations.PerformFiltering(DataSource, DataManagerRequest.Where, DataManagerRequest.Where[0].Operator); |
81 | 81 | } |
82 | | - // Handling Sorting in Custom Adaptor. |
| 82 | + // Handling Sorting in CustomAdaptor. |
83 | 83 | if (DataManagerRequest.Sorted != null && DataManagerRequest.Sorted.Count > 0) |
84 | 84 | { |
85 | 85 | // Sorting |
86 | 86 | DataSource = DataOperations.PerformSorting(DataSource, DataManagerRequest.Sorted); |
87 | 87 | } |
88 | | - int count = DataSource.Cast<Order>().Count(); |
89 | | - // Handling Aggregates in Custom Adaptor. |
| 88 | + int TotalRecordsCount = DataSource.Cast<Order>().Count(); |
| 89 | + // Handling Aggregates in CustomAdaptor. |
90 | 90 | IDictionary<string, object> Aggregates = null; |
91 | 91 | if (DataManagerRequest.Aggregates != null) // Aggregation |
92 | 92 | { |
93 | 93 | Aggregates = DataUtil.PerformAggregation(DataSource, DataManagerRequest.Aggregates); |
94 | 94 | } |
95 | | - // Handling Paging in Custom Adaptor. For example, Skip is 0 and Take is equal to page size for first page. |
| 95 | + // Handling Paging in CustomAdaptor. For example, Skip is 0 and Take is equal to page size for first page. |
96 | 96 | if (DataManagerRequest.Skip != 0) |
97 | 97 | { |
98 | 98 | //Paging |
|
102 | 102 | { |
103 | 103 | DataSource = DataOperations.PerformTake(DataSource, DataManagerRequest.Take); |
104 | 104 | } |
105 | | - // Handling Grouping in Custom Adaptor. |
| 105 | + // Handling Grouping in CustomAdaptor. |
106 | 106 | DataResult DataObject = new DataResult(); |
107 | 107 | if (DataManagerRequest.Group != null) |
108 | 108 | { |
|
113 | 113 | ResultData = DataUtil.Group<Order>(ResultData, group, DataManagerRequest.Aggregates, 0, DataManagerRequest.GroupByFormatter); |
114 | 114 | } |
115 | 115 | DataObject.Result = ResultData; |
116 | | - DataObject.Count = count; |
| 116 | + DataObject.Count = TotalRecordsCount; |
117 | 117 | //If both Grouping and Aggregate is enabled |
118 | 118 | if (DataManagerRequest.Aggregates != null) |
119 | 119 | { |
120 | 120 | DataObject.Aggregates = Aggregates; |
121 | 121 | } |
122 | | - //Here RequiresCount is passed from the control side itself, where ever the ondemand data fetching is needed then the RequiresCount is set as true in component side itself. |
123 | | - // In the above case we are using Paging so datas are loaded in ondemand bases whenever the next page is clicked in DataGrid side. |
| 122 | + //Here RequiresCount is passed from the control side itself, where ever the on-demand data fetching is needed then the RequiresCount is set as true in component side itself. |
| 123 | + // In the above case we are using paging so datas are loaded in on-demand bases whenever the next page is clicked in DataGrid side. |
124 | 124 | return DataManagerRequest.RequiresCounts ? DataObject : (object)ResultData; |
125 | 125 | } |
126 | | - //Here RequiresCount is passed from the control side itself, where ever the ondemand data fetching is needed then the RequiresCount is set as true in component side itself. |
127 | | - // In the above case we are using Paging so datas are loaded in ondemand bases whenever the next page is clicked in DataGrid side. |
128 | | - return DataManagerRequest.RequiresCounts ? new DataResult() { Result = DataSource, Count = count, Aggregates = Aggregates } : (object)DataSource; |
| 126 | + //Here RequiresCount is passed from the control side itself, where ever the on-demand data fetching is needed then the RequiresCount is set as true in component side itself. |
| 127 | + // In the above case we are using paging so datas are loaded in on-demand bases whenever the next page is clicked in DataGrid side. |
| 128 | + return DataManagerRequest.RequiresCounts ? new DataResult() { Result = DataSource, Count = TotalRecordsCount, Aggregates = Aggregates } : (object)DataSource; |
129 | 129 | } |
130 | 130 |
|
131 | 131 | /// <summary> |
|
170 | 170 | await OrderService.RemoveOrderAsync(Value as int?); |
171 | 171 | return Value; |
172 | 172 | } |
| 173 | + |
| 174 | + /// <summary> |
| 175 | + /// /// Batchupdate (Insert, Update, Delete) a collection of data items from the data collection. |
| 176 | + /// </summary> |
| 177 | + /// <param name="DataManager">The DataManager is a data management component used for performing data operations in application.</param> |
| 178 | + /// <param name="Changed">The Changed specifies the collection of record updated in batch mode which needs to be updated from the grid record.</param> |
| 179 | + /// <param name="Added">The Added specifies the collection of record inserted in batch mode which needs to be inserted from the grid record.</param> |
| 180 | + /// <param name="Deleted">The Deleted specifies the collection of record deleted in batch mode which needs to be removed from the grid record.</param> |
| 181 | + /// <param name="KeyField">The KeyField specifies the field name of the primary column.</param> |
| 182 | + /// <param name="Key">An optional parameter that can be used to perform additional data operations.</param> |
| 183 | + /// <param name="DropIndex">An optional parameter that can be used to perform row drag and drop operation.</param> |
| 184 | + /// <returns>Returns the removed data item.</returns> |
| 185 | + public override async Task<object> BatchUpdateAsync(DataManager DataManager, object Changed, object Added, object Deleted, string KeyField, string Key, int? DropIndex) |
| 186 | + { |
| 187 | + if (Changed != null) |
| 188 | + { |
| 189 | + foreach (var record in (IEnumerable<Order>)Changed) |
| 190 | + { |
| 191 | + await OrderService.UpdateOrderAsync(record as Order); |
| 192 | + } |
| 193 | + } |
| 194 | + if (Added != null) |
| 195 | + { |
| 196 | + foreach (var record in (IEnumerable<Order>)Added) |
| 197 | + { |
| 198 | + await OrderService.AddOrderAsync(record as Order); |
| 199 | + } |
| 200 | + } |
| 201 | + if (Deleted != null) |
| 202 | + { |
| 203 | + foreach (var record in (IEnumerable<Order>)Deleted) |
| 204 | + { |
| 205 | + await OrderService.RemoveOrderAsync((record as Order).OrderID); |
| 206 | + } |
| 207 | + } |
| 208 | + return Key; |
| 209 | + } |
173 | 210 | } |
174 | 211 | } |
175 | 212 |
|
0 commit comments