public IHttpActionResult Get() { var results = new { NumFoods = TheRepo.GetAllFoods().Count(), NumUsers = TheRepo.GetApiUsers().Count() }; return(Ok(results)); }
public IHttpActionResult Get(string name) { if (name == "foods") { return(Ok(new { NumFoods = TheRepo.GetAllFoods().Count() })); } if (name == "users") { return(Ok(new { NumUsers = TheRepo.GetApiUsers().Count() })); } return(NotFound()); }
public IHttpActionResult Get(int id) { if (id == 1) { return(Ok(new { NumFoods = TheRepo.GetAllFoods().Count() })); } if (id == 2) { return(Ok(new { NumUsers = TheRepo.GetApiUsers().Count() })); } return(NotFound()); }
public object Get(bool includeMeasures = true, int page = 0) { IQueryable <Food> query; if (includeMeasures) { query = TheRepo.GetAllFoodsWithMeasures(); } else { query = TheRepo.GetAllFoods(); } var baseQuery = query. OrderBy(f => f.Description); var totalCount = baseQuery.Count(); var totalPages = Math.Ceiling((double)totalCount / PAGE_SIZE); var url = new UrlHelper(Request); var prevUrl = page > 0?url.Link("Food", new { page = page - 1 }):""; var nextUrl = page < totalPages - 1?url.Link("Food", new { page = page + 1 }):""; var results = baseQuery .Skip(PAGE_SIZE * page) .Take(PAGE_SIZE) .ToList() .Select(f => TheModelFactory.Create(f)); return(new { TotalCount = totalCount, TotalPages = totalPages, PrevPageUrl = prevUrl, NextPageUrl = nextUrl, Results = results }); }