/// <summary> /// Calls the GetPopularTrips method of the ITripController and sorts the result based on the Popularity property. Send the data to the trip/Popular view. /// </summary> /// <returns>Returns the trip/popular view with the sorted data.</returns> public async Task <IActionResult> Popular() { var popular = await _trips.GetPopularTrips(); PopularTrip[] popArr = popular.ToArray(); bool sorted = false; while (sorted == false) { int count = 0; for (int i = 0; i < popArr.Length; i++) { if (i < popArr.Length - 1) { if (popArr[i].Popularity > popArr[i + 1].Popularity) { PopularTrip sort = popArr[i]; popArr[i] = popArr[i + 1]; popArr[i + 1] = sort; count++; } } } if (count == 0) { sorted = true; } } return(View(popArr)); }