private IQueryable <Suburb> PagingRequired(IQueryable <Suburb> query, SuburbQuery queryObject) { if (queryObject.Page != 0 || queryObject.PageSize != 0) { return(query.ApplyPaging(queryObject)); } return(query); }
private IQueryable <Suburb> FilteredRequired(IQueryable <Suburb> query, SuburbQuery queryObject, PropertyRentalContext context) { if (!String.IsNullOrWhiteSpace(queryObject.Postcode)) { query = query.Where(suburb => suburb.Postcode == queryObject.Postcode); } if (queryObject.StateId.HasValue) { query = query.Where(suburb => suburb.StateId == queryObject.StateId); } return(query); }
private IQueryable <Suburb> SortByRequired(IQueryable <Suburb> query, SuburbQuery queryObject) { if (!String.IsNullOrWhiteSpace(queryObject.SortBy)) { var columnsMap = new Dictionary <string, Expression <Func <Suburb, object> > >() { ["name"] = suburb => suburb.Name, ["postcode"] = suburb => suburb.Postcode, ["state"] = suburb => suburb.State.Name }; return(query.ApplyOrdering(queryObject, columnsMap)); } return(query); }
public async Task <QueryResult <Suburb> > GetSuburbs(SuburbQuery queryObject = null) { var queryResult = new QueryResult <Suburb>(); var query = context.Suburbs.Include(suburb => suburb.State).AsQueryable(); queryResult.TotalItems = await query.CountAsync(); if (queryObject != null) { query = this.FilteredRequired(query, queryObject, this.context); query = this.SortByRequired(query, queryObject); queryResult.TotalItems = await query.CountAsync(); query = this.PagingRequired(query, queryObject); } queryResult.Items = await query.ToListAsync(); return(queryResult); }