public ActionResult Connections() { IQueryable<Connection> query = connectionRepository.GetConnections(); var r = query.Select(x => new { id = x.Id, ppe = x.PPE, meterCode = x.MeterCode, name = x.Name, tariff = x.Tariff.Name, company = x.Company.Acronym, startDate = x.StartDate, endDate = x.EndDate, orderedCapacity = x.OrderedCapacity, endDateNullable = x.EndDate, orderedCapacityNullable = x.OrderedCapacity, isActive = x.Name.Length % 2 == 0 // fake boolean column }).ToArray(); return new JsonNetResult(r); }
public ActionResult Page(int startRow, int endRow, SortEntry[] sortModel, Dictionary <string, FilterEntry> filterModel, string globalFilter) { IQueryable <Connection> query = connectionRepository.GetConnections(); // if filters aren't posted, in filters we get values from MVC; with "action", "controller" as keys; they must be excluded, currently by their null value criterion foreach (var kvp in filterModel.Where(x => x.Value != null)) { // get expression for this column LambdaExpression columnExpression = columnSource[kvp.Key]; // convert grid-specific filter to an universal entry UniversalFilterEntry universalFilterEntry = FilterEntryConverter.Convert(kvp.Value); // check whether the entry was parsed successfully if (universalFilterEntry == null) { continue; } // get the fltering expression from universalFilterEntry Expression <Func <Connection, bool> > filterExpression = FilterExpressions <Connection> .GetFilterExpression(columnExpression, universalFilterEntry); // and apply it to the query query = query.Where(filterExpression); } // global filtering if (String.IsNullOrWhiteSpace(globalFilter) == false) { query = query.Where(x => x.Name.Contains(globalFilter) || x.PPE.Contains(globalFilter) || x.MeterCode.Contains(globalFilter) || x.Company.Acronym.Contains(globalFilter) || x.Tariff.Name.Contains(globalFilter)); } int count = query.Count(); if (sortModel != null) { for (int i = 0; i < sortModel.Length; i++) { SortEntry sortEntry = sortModel[i]; string column = sortEntry.colId; bool isAsc = sortEntry.sort == SortEntry.asc; bool isFirst = i == 0; LambdaExpression columnExpression = columnSource[column]; query = SortHelper.ApplyOrderByFromLambda(query, columnExpression, isAsc, isFirst); } } else { query = query.OrderBy(x => x.Name); } var r = query.Skip(startRow).Take(endRow - startRow).Select(x => new { id = x.Id, ppe = x.PPE, meterCode = x.MeterCode, name = x.Name, tariff = x.Tariff.Name, company = x.Company.Acronym, startDate = x.StartDate, endDate = x.EndDate, orderedCapacity = x.OrderedCapacity, endDateNullable = x.EndDate, orderedCapacityNullable = x.OrderedCapacity, isActive = x.Name.Length % 2 == 0 // fake boolean column }).ToArray(); var response = new { rows = r, count = count }; return(new JsonNetResult(response)); }