namespace Dumball.Controllers { [HandleError] public class HomeController : Controller { private static IEnumerable fundraisers = new List(); private static DateTime justGivingCacheExpiry = DateTime.Now; public static IEnumerable FundRaisers { get { try { if (DateTime.Now.CompareTo(justGivingCacheExpiry) > 0) { fundraisers = new List(); int currentPage = 1; int totalPages = 0; do { XDocument fundraiserPages = XDocument.Load(string.Format("https://api.justgiving.com/59b1dd3d/v1/event/718649/pages?page={0}", currentPage)); totalPages = int.Parse(fundraiserPages.Root.Element("totalPages").Value); currentPage++; fundraisers = fundraisers.Concat( from justGivingPage in fundraiserPages.Descendants("fundraisingPage") where justGivingPage.Element("pageStatus").Value == "Active" select new Dumball.Models.FundRaiser( justGivingPage.Element("pageTitle").Value, Decimal.Parse(justGivingPage.Element("raisedAmount").Value), int.Parse(justGivingPage.Element("pageId").Value), justGivingPage.Element("pageShortName").Value)); } while (currentPage <= totalPages); justGivingCacheExpiry = DateTime.Now.AddMinutes(30); } return fundraisers; } catch (Exception) { return null; } } } public ActionResult Totaliser() { return View(FundRaisers.OrderByDescending(i => i.Amount).AsEnumerable() ?? new List()); } } }