public IEnumerable Get([FromUri] FilterModel filter) { var persons = DataSources.Persons.AsQueryable(); //Expression<Func<Person, object>> orderExpression = (x => x.GetType().GetProperty(filter.SortName).GetValue(x)); persons = persons .Skip(filter.SkipCount) .Take(filter.Size); if (!string.IsNullOrEmpty(filter.SortName)) { persons = filter.SortOrder == FilterModel.SortingOrder.Desc ? persons.OrderByDescending(filter.GetSortingExpression <Person, string>()) : persons.OrderBy(filter.GetSortingExpression <Person, string>()); } return(persons.ToList()); }
public IEnumerable GetWithFullname([FromUri] FilterModel filter) { var customObjectCollection = DataSources.Persons.AsQueryable() .Skip(filter.SkipCount) .Take(filter.Size) .Select(x => new PersonFullName { FirstName = x.FirstName, LastName = x.LastName, FullName = x.FirstName + " " + x.LastName }); if (!string.IsNullOrEmpty(filter.SortName)) { customObjectCollection = filter.SortOrder == FilterModel.SortingOrder.Desc ? customObjectCollection.OrderByDescending(filter.GetSortingExpression <PersonFullName, string>()) : customObjectCollection.OrderBy(filter.GetSortingExpression <PersonFullName, string>()); } return(customObjectCollection.ToList()); }