//private string _calendarResponseAsString;

        public iCalFormatResult(string contentType, object calendar)
           // : base(contentType)
        {
            _contentType = contentType;
            _calendarView = calendar as CalendarViewModel;
            if (_calendarView == null)
            {
                _eventIcs = calendar as EventIcs;
                if (_eventIcs == null)
                {
                    throw new InvalidOperationException("Cannot serialize type");
                }
            }

        }
        public void WriteAppointmentToStringBuilder(EventIcs evt, StringBuilder writer)
        {

            writer.AppendLine("BEGIN:VEVENT");
            writer.AppendLine("UID:" + evt.Id + "@nflpa.com");
            if (evt.IsAllDay)
            {
                writer.AppendLine("DTSTART;VALUE=DATE:" +
                    string.Format("{0:yyyyMMdd}", evt.Start));
                writer.AppendLine("DTEND;VALUE=DATE:" +
                    string.Format("{0:yyyyMMdd}", evt.End));
            }
            else
            {
                writer.AppendLine("DTSTART;TZID=" + evt.TimeZone + ":" +
                    string.Format("{0:yyyyMMddTHHmmssZ}", evt.Start));
                writer.AppendLine("DTEND;TZID=" + evt.TimeZone + ":" +
                    string.Format("{0:yyyyMMddTHHmmssZ}", evt.End));
            }
            writer.AppendLine("SUMMARY:" + evt.Title);
            writer.AppendLine("DESCRIPTION:" + evt.Summary);
            //if (!string.IsNullOrWhiteSpace(evt.LocationName))
            writer.AppendLine("LOCATION:" + evt.LocationName);
            if (!string.IsNullOrWhiteSpace(evt.CategoriesCsv))
                writer.AppendLine("CATEGORIES:" + evt.CategoriesCsv);
            writer.AppendLine("DTSTAMP:" + string.Format("{0:yyyyMMddTHHmmssZ}", evt.ModifiedDateTime));
            writer.AppendLine("CREATED:" + string.Format("{0:yyyyMMddTHHmmssZ}", evt.CreateDateTime));
            writer.AppendLine("URL:" + evt.Url);
            writer.AppendLine("END:VEVENT");
        }
 public EventIcs GetEventIcs(EventPart x)
 {
     var data = new EventIcs
     {
         IsAllDay = x.AllDayEvent,
         Id = x.Identifier,
         Title = x.Title,
         Start = Convert.ToDateTime(x.StartDate),//TimeZoneHelper.ConvertTZIDFromUTC(x.StartDate, x.TimeZone),
         End = Convert.ToDateTime(x.EndDate),//TimeZoneHelper.ConvertTZIDFromUTC(x.EndDate, x.TimeZone),
         CreateDateTime = Convert.ToDateTime(x.CreateUtc),
         ModifiedDateTime = Convert.ToDateTime(x.ModifiedUtc),
         PublishDateTime = Convert.ToDateTime(x.PublishedUtc),
         CategoriesCsv = string.Join(",", x.Categories.Select(y => y.CategoryName)),
         LocationName = x.AddressLocation,
         TimeZone = string.IsNullOrWhiteSpace(x.TimeZone) ? "America/New_York" : x.TimeZone,
         RecurrenceId = x.RecurrenceId,
         RecurrenceRule = x.RecurrenceRule,
         RecurrenceException = x.RecurrenceException,
         Url = x.Url
     };
     if (!string.IsNullOrEmpty(x.Url))
     {
         data.Url = x.Url;
     }
     else
     {
         var autoroute = x.ContentItem.As<AutoroutePart>();
         if (autoroute != null)
         {
             data.Url = _siteService.GetSiteSettings().BaseUrl + "/" + autoroute.Path;
         }
     }
     return data;
 }