public IActionResult StudentsAjax(DateTime date)
 {
     if (cache.Contains(date))
     {
         var vertretungsplan = cache.Find(date);
         var tag             = helper.GenerateETagSingle(vertretungsplan, User.Identity.Name, true);
         return(cachingHelper.UseETag(tag) ?? PartialView("Students", helper.GenerateViewModel(VertretungsplanType.Students, vertretungsplan)));
     }
     else
     {
         return(new StatusCodeResult(StatusCodes.Status404NotFound));
     }
 }
        public IActionResult Get(DateTime date)
        {
            var vertretungsplan = cache.Find(date);

            if (vertretungsplan == null)
            {
                return(NotFound());
            }
            return(Ok(vertretungsplan));
        }
Ejemplo n.º 3
0
        async Task LoadDataFromApi()
        {
            var response = await client.GetAsync("/dates?metadata");

            if (!response.IsSuccessStatusCode)
            {
                return;
            }

            var json = await response.Content.ReadAsStringAsync();

            var dates = JsonConvert.DeserializeObject <List <VertretungsplanMetadata> >(json);

            if (dates == null)
            {
                return;
            }

            foreach (var loaded in dates)
            {
                var cached     = cache.Find(loaded.Date);
                var dateExists = cached != null;

                // New or more recent than existing version
                if (!dateExists || loaded.LastUpdated > cached.LastUpdated || loaded.Version > cached.Version)
                {
                    var dateResponse = await client.GetAsync("/dates/" + loaded.Date.ToString("yyyy-MM-dd"));

                    var dateJson = await dateResponse.Content.ReadAsStringAsync();

                    var vp = JsonConvert.DeserializeObject <Vertretungsplan>(dateJson);
                    cache.Add(vp);
                }
            }

            var oldDates = cache.GetAllDates().Except(dates.Select(vp => vp.Date)).ToList();

            foreach (var old in oldDates)
            {
                cache.Remove(old);
            }
        }