public ActionResult Get(int take = -1, int skip = -1, float lat = 0, float lng = 0, string profiles = "", bool personalize = true) { try { // fetching profile names from the action parameter var profileNames = string.IsNullOrWhiteSpace(profiles) ? new string[0] : profiles.Split('|'); // or loading from the tracker if not specified if (personalize && !profileNames.Any()) { profileNames = Tracker.Current.GetPopulatedProfilesFromTracker(); } var allItems = dataService.GetAll(Context.Database, profileNames, take, skip, lat, lng, out int totalSearchResults); if (personalize) { var scoredItems = itemScoringService.ScoreItems(allItems, Context.Database); // return scored items only if anything was returned if (scoredItems.Any()) { allItems = scoredItems; } } var events = new JArray(allItems.Select(i => JObject.Parse(itemSerializer.Serialize(i)))); var results = new JObject { { "events", events }, { "total", totalSearchResults } }; return(Content(results.ToString(), "application/json")); } catch (Exception ex) { Log.Error("Unable to retrieve events", ex, this); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message)); } }
public ActionResult Get(int take = 5) { try { var allItems = dataService.GetAll(Context.Database); var scoredItems = itemScoringService.ScoreItems(allItems, Context.Database); // if no items were scrored - return the original item list if (!scoredItems.Any()) { scoredItems = allItems; } var items = new JArray(scoredItems.Take(take).Select(i => JObject.Parse(itemSerializer.Serialize(i)))); return(Content(items.ToString(), "application/json")); } catch (Exception ex) { Log.Error("Unable to retrieve events", ex, this); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message)); } }