public DayData UpdateDay(DateTime day, string data)
 {
     var lineStrings = data.Split('\n');
     List<DayLine> lines = new List<DayLine>();
     foreach (var lineString in lineStrings)
         lines.Add(new DayLine(lineString.Trim()));
     var existing = _collection.Data.FirstOrDefault(d => d.Day == day);
     if (existing == null)
     {
         existing = new DayData { Day = day, Lines = lines };
         _collection.Data.Add(existing);
     }
     else
         existing.Lines = lines;
     var xSer = new XmlSerializer(typeof(DayCollection));
     using (var fs = File.Open(_path, FileMode.Create))
     {
         xSer.Serialize(fs, _collection);
     }
     return existing;
 }
 public ActionResult Calendar(int month, int day, int year)
 {
     DateTime startDate = new DateTime(year, month, day);
     ViewData["date"] = startDate;
     var repo = new CalendarRepository(Server.MapPath("~/App_Data"));
     var data = repo.GetData(startDate, 35);
     var tracks = (from t in _tracks.Tracks where t.TrackDate >= startDate && t.TrackDate <= startDate.AddDays(35) select t);
     foreach (var d in Enumerable.Range(0, 35).Select(i => startDate.AddDays(i)))
     {
         var dayTracks = (from t in tracks where t.TrackDate >= d && t.TrackDate <= d.AddDays(1) select t).ToList();
         if (dayTracks != null && dayTracks.Count > 0)
         {
             var dayData = (from dd in data.Data where dd.Day == d select dd).FirstOrDefault();
             if (dayData == null)
             {
                 dayData = new DayData { Day = d, Tracks = dayTracks };
                 data.Data.Add(dayData);
             }
             dayData.Tracks = dayTracks;
         }
     }
     return View(data);
 }