/// <summary> /// CanProduceOccurrences, /// This will return true if this event is capable of generating occurrences, otherwise false. /// For performance reasons, it is a good idea to include a limit on the number of years that are /// searched for occurrences. (For example, 110 years). /// /// If no limit is supplied, and the event has no end date, then this function can /// (in the worst-case scenario) search for an occurrence until DateTime.MaxDate which is the year 9999, /// which can take a lot of processing time. /// </summary> public bool CanProduceOccurrences(int?withinYears) { if (HasBrokenZeroOccurrenceConfiguration()) { return(false); } DateRange eventLimits = GetEventLimitsAsDateRange(); int daysInRange = eventLimits.GetNumberOfDaysInRange(); int maximumDaysWithoutOccurrence = RepeatInterval; switch (FrequencyTypeOptions) { case FrequencyTypeEnum.Daily: break; case FrequencyTypeEnum.Weekly: case FrequencyTypeEnum.EveryWeekDay: case FrequencyTypeEnum.EveryMonWedFri: case FrequencyTypeEnum.EveryTuTh: maximumDaysWithoutOccurrence *= 7; break; case FrequencyTypeEnum.Monthly: maximumDaysWithoutOccurrence *= 31; break; case FrequencyTypeEnum.Quarterly: maximumDaysWithoutOccurrence *= 96; break; case FrequencyTypeEnum.Yearly: // Leap years have 366 days. maximumDaysWithoutOccurrence *= 366; break; } if (daysInRange > maximumDaysWithoutOccurrence) { return(true); } Schedule schedule = new Schedule(this); DateTime?occurrence; if (withinYears != null) { occurrence = schedule.NextOccurrence(eventLimits.StartDateTime, new DateRange(eventLimits.StartDateTime, eventLimits.StartDateTime.SafeAddYears((int)withinYears))); } else { occurrence = schedule.NextOccurrence(eventLimits.StartDateTime, new DateRange(eventLimits.StartDateTime, eventLimits.EndDateTime)); } if (occurrence != null) { return(true); } return(false); }
public void MonthTest1() { var aEvent = new Event() { ID = 1, Title = "Event 1", FrequencyTypeOptions = FrequencyTypeEnum.Monthly, MonthlyIntervalOptions = MonthlyIntervalEnum.EveryWeek, DaysOfWeekOptions = DayOfWeekEnum.Mon | DayOfWeekEnum.Fri }; var range = new DateRange() { StartDateTime = new DateTime(2013, 1, 15), EndDateTime = new DateTime(2013, 4, 30) }; var occurringDate = new DateTime(2013, 1, 21); var schedule = new Schedule(aEvent); Assert.IsTrue(schedule.IsOccurring(occurringDate)); var previousOccurrence = schedule.PreviousOccurrence(occurringDate, range); Assert.AreEqual(new DateTime(2013, 1, 18), previousOccurrence.Value); var nextOccurrence = schedule.NextOccurrence(occurringDate, range); Assert.AreEqual(new DateTime(2013, 1, 25), nextOccurrence.Value); var occurrences = schedule.Occurrences(range); Assert.AreEqual(30, occurrences.Count()); Assert.AreEqual(new DateTime(2013, 1, 18), occurrences.First()); Assert.AreEqual(new DateTime(2013, 4, 29), occurrences.Last()); }
public void RecurringScheduleNextOccurrenceTest2() { var aEvent = CreateRecurringEvent(); var schedule = new Schedule(aEvent); Assert.IsNotNull(schedule); var nextOccurrence = schedule.NextOccurrence(new DateTime(2012, 12, 19)); Assert.IsTrue(nextOccurrence == new DateTime(2013, 1, 2)); }
public ActionResult GetEventDetails(int id, int type = 0) { EventLocation l = null; EventDetailsModel evm = null; if (type == 0) { CalendarEntry e = ApplicationContext.DatabaseContext.Database.Single<CalendarEntry>("SELECT * FROM ec_events WHERE id=@0", id); if (e.locationId != 0) { l = ApplicationContext.DatabaseContext.Database.Single<EventLocation>("SELECT * FROM ec_locations WHERE id = @0", e.locationId); } evm = new EventDetailsModel() { Title = e.title, Description = e.description, LocationId = e.locationId, Location = l }; if (null != e.start) { evm.StartDate = ((DateTime)e.start).ToString("F", CultureInfo.CurrentCulture); } if (null != e.end) { evm.EndDate = ((DateTime)e.end).ToString("F", CultureInfo.CurrentCulture); } } else if (type == 1) { RecurringEvent e = ApplicationContext.DatabaseContext.Database.Single<RecurringEvent>("SELECT * FROM ec_recevents WHERE id=@0", id); if (e.locationId != 0) { l = ApplicationContext.DatabaseContext.Database.Single<EventLocation>("SELECT * FROM ec_locations WHERE id = @0", e.locationId); } Schedule schedule = new Schedule(new Event() { Title = e.title, DaysOfWeekOptions = (DayOfWeekEnum)e.day, FrequencyTypeOptions = (FrequencyTypeEnum)e.frequency, MonthlyIntervalOptions = (MonthlyIntervalEnum)e.monthly_interval }); evm = new EventDetailsModel() { Title = e.title, Description = e.description, LocationId = e.locationId, Location = l, StartDate = ((DateTime)schedule.NextOccurrence(DateTime.Now)).ToString("F", CultureInfo.CurrentCulture) }; } return PartialView("EventDetails",evm); }
public void EventOptionsNextOccurrenceTest() { var holidays = GetHolidays(); var aEvent = CreateStreetCleaningEvent(); var schedule = new Schedule(aEvent, holidays); Assert.IsNotNull(holidays); Assert.IsNotNull(aEvent); Assert.IsNotNull(schedule); var next = schedule.NextOccurrence(new DateTime(2016, 6, 6)); Assert.IsTrue(next.Equals(new DateTime(2016, 6, 20))); Assert.IsFalse(next.Equals(new DateTime(2016, 5, 16))); Assert.IsFalse(next.Equals(new DateTime(2016, 6, 6))); }
public void RecurringScheduleExclusionsTest2() { var aEvent = CreateRecurringEvent(); var excludedDays = new List<DateTime>() { new DateTime(2012, 12, 5), new DateTime(2012, 12, 25), new DateTime(2013, 1, 2), new DateTime(2013, 2, 18) }; var schedule = new Schedule(aEvent, excludedDays); Assert.IsNotNull(schedule); var nextOccurrence = schedule.NextOccurrence(new DateTime(2013, 1, 1)); Assert.IsTrue(nextOccurrence == new DateTime(2013, 1, 7)); }
public void MonthTest2() { var aEvent = new Event() { ID = 1, Title = "Event 2", FrequencyTypeOptions = FrequencyTypeEnum.Monthly, RepeatInterval = 2, MonthlyIntervalOptions = MonthlyIntervalEnum.Last, DaysOfWeekOptions = DayOfWeekEnum.Mon | DayOfWeekEnum.Fri, StartDateTime = new DateTime(2013, 1, 15) }; var range = new DateRange() { StartDateTime = aEvent.StartDateTime.Value, EndDateTime = new DateTime(2013, 4, 30) }; var nonOccurringDate = new DateTime(2013, 1, 29); var schedule = new Schedule(aEvent); Assert.IsFalse(schedule.IsOccurring(nonOccurringDate)); var previousOccurrence = schedule.PreviousOccurrence(nonOccurringDate, range); Assert.AreEqual(new DateTime(2013, 1, 28), previousOccurrence.Value); var nextOccurrence = schedule.NextOccurrence(nonOccurringDate, range); Assert.AreEqual(new DateTime(2013, 3, 25), nextOccurrence.Value); var occurrences = schedule.Occurrences(range); Assert.AreEqual(4, occurrences.Count()); Assert.AreEqual(new DateTime(2013, 1, 25), occurrences.First()); Assert.AreEqual(new DateTime(2013, 3, 29), occurrences.Last()); }
/// <summary> /// CanProduceOccurrences, /// This will return true if this event is capable of generating occurrences, otherwise false. /// For performance reasons, it is a good idea to include a limit on the number of years that are /// searched for occurrences. (For example, 110 years). /// /// If no limit is supplied, and the event has no end date, then this function can /// (in the worst-case scenario) search for an occurrence until DateTime.MaxDate which is the year 9999, /// which can take a lot of processing time. /// </summary> public bool CanProduceOccurrences(int? withinYears) { if (HasBrokenZeroOccurrenceConfiguration()) return false; DateRange eventLimits = GetEventLimitsAsDateRange(); int daysInRange = eventLimits.GetNumberOfDaysInRange(); int maximumDaysWithoutOccurrence = RepeatInterval; switch (FrequencyTypeOptions) { case FrequencyTypeEnum.Daily: break; case FrequencyTypeEnum.Weekly: case FrequencyTypeEnum.EveryWeekDay: case FrequencyTypeEnum.EveryMonWedFri: case FrequencyTypeEnum.EveryTuTh: maximumDaysWithoutOccurrence *= 7; break; case FrequencyTypeEnum.Monthly: maximumDaysWithoutOccurrence *= 31; break; case FrequencyTypeEnum.Quarterly: maximumDaysWithoutOccurrence *= 96; break; case FrequencyTypeEnum.Yearly: // Leap years have 366 days. maximumDaysWithoutOccurrence *= 366; break; } if (daysInRange > maximumDaysWithoutOccurrence) return true; Schedule schedule = new Schedule(this); DateTime? occurrence; if (withinYears != null) { occurrence = schedule.NextOccurrence(eventLimits.StartDateTime, new DateRange(eventLimits.StartDateTime, eventLimits.StartDateTime.SafeAddYears((int)withinYears))); } else { occurrence = schedule.NextOccurrence(eventLimits.StartDateTime, new DateRange(eventLimits.StartDateTime, eventLimits.EndDateTime)); } if (occurrence != null) { return true; } return false; }
public void MonthTest3() { var aEvent = new Event() { ID = 1, Title = "Event 3", FrequencyTypeOptions = FrequencyTypeEnum.Monthly, DayOfMonth = 3 }; var range = new DateRange() { StartDateTime = new DateTime(2013, 1, 1), EndDateTime = new DateTime(2014, 12, 31) }; var occurringDate = new DateTime(2013, 12, 3); var schedule = new Schedule(aEvent); Assert.IsTrue(schedule.IsOccurring(occurringDate)); var previousOccurrence = schedule.PreviousOccurrence(occurringDate, range); Assert.AreEqual(new DateTime(2013, 11, 3), previousOccurrence.Value); var nextOccurrence = schedule.NextOccurrence(occurringDate, range); Assert.AreEqual(new DateTime(2014, 1, 3), nextOccurrence.Value); var occurrences = schedule.Occurrences(range); Assert.AreEqual(24, occurrences.Count()); Assert.AreEqual(new DateTime(2013, 1, 3), occurrences.First()); Assert.AreEqual(new DateTime(2014, 12, 3), occurrences.Last()); }
public void MonthTest5() { var holidays = new UnionTE(); holidays.Add(new FixedHolidayTE(1, 25)); holidays.Add(new FloatingHolidayTE(3, DayOfWeekEnum.Mon, MonthlyIntervalEnum.First)); var aEvent = new Event() { ID = 1, Title = "Event 5", FrequencyTypeOptions = FrequencyTypeEnum.Monthly, MonthlyIntervalOptions = MonthlyIntervalEnum.EveryWeek, DaysOfWeekOptions = DayOfWeekEnum.Mon | DayOfWeekEnum.Fri }; var range = new DateRange() { StartDateTime = new DateTime(2013, 1, 15), EndDateTime = new DateTime(2013, 4, 30) }; var occurringDate = new DateTime(2013, 1, 21); var schedule = new Schedule(aEvent, holidays); Assert.IsTrue(schedule.IsOccurring(occurringDate)); Assert.IsFalse(schedule.IsOccurring(new DateTime(2013, 3, 4))); var previousOccurrence = schedule.PreviousOccurrence(occurringDate, range); Assert.AreEqual(new DateTime(2013, 1, 18), previousOccurrence.Value); var nextOccurrence = schedule.NextOccurrence(occurringDate, range); Assert.AreEqual(new DateTime(2013, 1, 28), nextOccurrence.Value); var occurrences = schedule.Occurrences(range); Assert.AreEqual(28, occurrences.Count()); Assert.AreEqual(new DateTime(2013, 1, 18), occurrences.First()); Assert.AreEqual(new DateTime(2013, 4, 29), occurrences.Last()); }
public void MonthTest4() { var aEvent = new Event() { ID = 1, Title = "Event 4", FrequencyTypeOptions = FrequencyTypeEnum.Monthly, RepeatInterval = 3, DayOfMonth = 30, StartDateTime = new DateTime(2013, 2, 1) }; var range = new DateRange() { StartDateTime = aEvent.StartDateTime.Value, EndDateTime = new DateTime(2014, 12, 31) }; var occurringDate = new DateTime(2014, 2, 28); var schedule = new Schedule(aEvent); Assert.IsTrue(schedule.IsOccurring(occurringDate)); var previousOccurrence = schedule.PreviousOccurrence(occurringDate, range); Assert.AreEqual(new DateTime(2013, 11, 30), previousOccurrence.Value); var nextOccurrence = schedule.NextOccurrence(occurringDate, range); Assert.AreEqual(new DateTime(2014, 5, 30), nextOccurrence.Value); var occurrences = schedule.Occurrences(range); Assert.AreEqual(8, occurrences.Count()); Assert.AreEqual(new DateTime(2013, 2, 28), occurrences.First()); Assert.AreEqual(new DateTime(2014, 11, 30), occurrences.Last()); }
public ActionResult GetEventDetails(int id, int calendar, int type = 0) { EventLocation l = null; EventDetailsModel evm = null; var lctrl = new LocationApiController(); if (type == 0) { //Fetch Event var ectrl = new EventApiController(); var e = ectrl.GetById(id); //If it has a location fetch it if (e.locationId != 0) { l = lctrl.GetById(e.locationId); } evm = new EventDetailsModel() { Title = e.title, LocationId = e.locationId, Location = l, Descriptions = e.descriptions }; if (null != e.start) { evm.StartDate = ((DateTime)e.start).ToString("F", CultureInfo.CurrentCulture); } if (null != e.end) { evm.EndDate = ((DateTime)e.end).ToString("F", CultureInfo.CurrentCulture); } } else if (type == 1) { var ectrl = new REventApiController(); var e = ectrl.GetById(id); if (e.locationId != 0) { l = lctrl.GetById(e.locationId); } Schedule schedule = new Schedule(new ScheduleWidget.ScheduledEvents.Event() { Title = e.title, DaysOfWeekOptions = (DayOfWeekEnum)e.day, FrequencyTypeOptions = (FrequencyTypeEnum)e.frequency, MonthlyIntervalOptions = (MonthlyIntervalEnum)e.monthly_interval }); evm = new EventDetailsModel() { Title = e.title, LocationId = e.locationId, Location = l, StartDate = ((DateTime)schedule.NextOccurrence(DateTime.Now)).ToString("F", CultureInfo.CurrentCulture), Descriptions = e.descriptions }; } return PartialView("EventDetails", evm); }
public void MultifunctionTest1() { var aEvent = new Event() { FrequencyTypeOptions = FrequencyTypeEnum.Yearly, RepeatInterval = 2, StartDateTime = new DateTime(2000, 9, 27), // even years only Anniversary = new Anniversary() { Month = 9, Day = 27 } }; // Occurs 2000,2002,2004,2006,2008,2010 aEvent.SetEndDateWithNumberOfOccurrences(6); // Check that the ending date was set correctly. Assert.IsTrue(aEvent.EndDateTime == new DateTime(2010, 9, 27)); // Check that the number of occurrences is retrievable. Assert.IsTrue(aEvent.NumberOfOccurrencesThatWasLastSet == 6); // Exclude 2000,2006,2010. var excludedDates = new List<DateTime> { new DateTime(2000, 9, 27), new DateTime(2005, 9, 27), new DateTime(2005, 9, 28), new DateTime(2006, 9, 27), new DateTime(2010, 9, 27) }; var schedule = new Schedule(aEvent, excludedDates); // Make sure it is not occurring on excluded dates. Assert.IsFalse(schedule.IsOccurring(new DateTime(2000, 9, 27))); Assert.IsFalse(schedule.IsOccurring(new DateTime(2006, 9, 27))); Assert.IsFalse(schedule.IsOccurring(new DateTime(2010, 9, 27))); // Make sure it is not occurring outside the set range. Assert.IsFalse(schedule.IsOccurring(new DateTime(1998, 9, 27))); Assert.IsFalse(schedule.IsOccurring(new DateTime(2012, 9, 27))); // Make sure it is occurring on desired dates. Assert.IsTrue(schedule.IsOccurring(new DateTime(2002, 9, 27))); Assert.IsTrue(schedule.IsOccurring(new DateTime(2004, 9, 27))); Assert.IsTrue(schedule.IsOccurring(new DateTime(2008, 9, 27))); // Check the occurrences function. var during = new DateRange(new DateTime(1995, 1, 1),new DateTime(2015, 1, 1)); var occurrences = schedule.Occurrences(during); Assert.IsTrue(occurrences.Count() == 3); // Check the last occurrence date function. var lastDate = schedule.GetLastOccurrenceDate(); Assert.IsTrue(lastDate == new DateTime(2008, 9, 27)); // Check the next occurrence (date only) function. Assert.IsTrue(schedule.NextOccurrence(new DateTime(1995, 1, 1)) == new DateTime(2002, 9, 27)); Assert.IsTrue(schedule.NextOccurrence(new DateTime(2004, 9, 26)) == new DateTime(2004, 9, 27)); Assert.IsTrue(schedule.NextOccurrence(new DateTime(2004, 9, 27)) == new DateTime(2008, 9, 27)); Assert.IsTrue(schedule.NextOccurrence(new DateTime(2008, 9, 27)) == null); // Check the previous occurrence (date only) function. Assert.IsTrue(schedule.PreviousOccurrence(new DateTime(1995, 1, 1)) == null); Assert.IsTrue(schedule.PreviousOccurrence(new DateTime(2004, 9, 26)) == new DateTime(2002, 9, 27)); Assert.IsTrue(schedule.PreviousOccurrence(new DateTime(2004, 9, 28)) == new DateTime(2004, 9, 27)); Assert.IsTrue(schedule.PreviousOccurrence(new DateTime(2013, 9, 27)) == new DateTime(2008, 9, 27)); // Check the next occurrence ranged function. var range1 = new DateRange(new DateTime(2004, 9, 1), new DateTime(2004, 10, 1)); var range2 = new DateRange(new DateTime(2004, 11, 1), new DateTime(2002, 9, 27)); Assert.IsTrue(schedule.NextOccurrence(new DateTime(1995, 1, 1), range1) == new DateTime(2004, 9, 27)); Assert.IsTrue(schedule.NextOccurrence(new DateTime(1995, 1, 1), range2) == null); // Check the previous occurrence ranged function. Assert.IsTrue(schedule.PreviousOccurrence(new DateTime(2015, 1, 1), range1) == new DateTime(2004, 9, 27)); Assert.IsTrue(schedule.PreviousOccurrence(new DateTime(2015, 1, 1), range2) == null); }
public ActionResult GetIcsForCalendar(int id) { DDay.iCal.iCalendar iCal = new DDay.iCal.iCalendar(); var lctrl = new LocationApiController(); var calctrl = new CalendarApiController(); var cal = calctrl.GetById(id); EventLocation l = null; iCal.Properties.Add(new CalendarProperty("X-WR-CALNAME", cal.Calendarname)); //Get normal events for calendar var nectrl = new EventApiController(); foreach (var e in nectrl.GetAll().Where(x => x.calendarId == id)) { // Create the event, and add it to the iCalendar DDay.iCal.Event evt = iCal.Create<DDay.iCal.Event>(); var start = (DateTime)e.start; evt.Start = new iCalDateTime(start.ToUniversalTime()); if (e.end != null) { var end = (DateTime)e.end; evt.End = new iCalDateTime(end.ToUniversalTime()); } evt.Description = this.GetDescription(e, CultureInfo.CurrentCulture.ToString()); evt.Summary = e.title; evt.IsAllDay = e.allDay; evt.Categories.AddRange(e.categories.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList()); //If it has a location fetch it if (e.locationId != 0) { l = lctrl.GetById(e.locationId); evt.Location = l.LocationName + "," + l.Street + "," + l.ZipCode + " " + l.City + "," + l.Country; //evt.GeographicLocation = new GeographicLocation(Convert.ToDouble(l.lat,CultureInfo.InvariantCulture), Convert.ToDouble(l.lon, CultureInfo.InvariantCulture)); } var attendes = new List<IAttendee>(); if (e.Organisator != null && e.Organisator != 0) { var ms = Services.MemberService; var member = ms.GetById(e.Organisator); string attendee = "MAILTO:" + member.Email; IAttendee reqattendee = new DDay.iCal.Attendee(attendee) { CommonName = member.Name, Role = "REQ-PARTICIPANT" }; attendes.Add(reqattendee); } if (attendes != null && attendes.Count > 0) { evt.Attendees = attendes; } } //Get recurring events var rectrl = new REventApiController(); foreach(var e in rectrl.GetAll().Where(x => x.calendarId == id)) { // Create the event, and add it to the iCalendar DDay.iCal.Event evt = iCal.Create<DDay.iCal.Event>(); evt.Description = this.GetDescription(e, CultureInfo.CurrentCulture.ToString()); evt.Summary = e.title; evt.IsAllDay = e.allDay; evt.Categories.AddRange(e.categories.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList()); //If it has a location fetch it if (e.locationId != 0) { l = lctrl.GetById(e.locationId); evt.Location = l.LocationName + "," + l.Street + "," + l.ZipCode + " " + l.City + "," + l.Country; //evt.GeographicLocation = new GeographicLocation(Convert.ToDouble(l.lat, CultureInfo.InvariantCulture), Convert.ToDouble(l.lon, CultureInfo.InvariantCulture)); } RecurrencePattern rp = null; var frequency = (FrequencyTypeEnum)e.frequency; switch (frequency) { case FrequencyTypeEnum.Daily: { rp = new RecurrencePattern(FrequencyType.Daily); break; } case FrequencyTypeEnum.Monthly: { rp = new RecurrencePattern(FrequencyType.Monthly); break; } case FrequencyTypeEnum.Weekly: { rp = new RecurrencePattern(FrequencyType.Weekly); break; } case FrequencyTypeEnum.Yearly: { rp = new RecurrencePattern(FrequencyType.Yearly); break; } default: { rp = new RecurrencePattern(FrequencyType.Monthly); break; } } switch (e.day) { case (int)DayOfWeekEnum.Mon: { rp.ByDay.Add(new WeekDay(DayOfWeek.Monday)); break; } case (int)DayOfWeekEnum.Tue: { rp.ByDay.Add(new WeekDay(DayOfWeek.Tuesday)); break; } case (int)DayOfWeekEnum.Wed: { rp.ByDay.Add(new WeekDay(DayOfWeek.Wednesday)); break; } case (int)DayOfWeekEnum.Thu: { rp.ByDay.Add(new WeekDay(DayOfWeek.Thursday)); break; } case (int)DayOfWeekEnum.Fri: { rp.ByDay.Add(new WeekDay(DayOfWeek.Friday)); break; } case (int)DayOfWeekEnum.Sat: { rp.ByDay.Add(new WeekDay(DayOfWeek.Saturday)); break; } case (int)DayOfWeekEnum.Sun: { rp.ByDay.Add(new WeekDay(DayOfWeek.Sunday)); break; } } evt.RecurrenceRules.Add(rp); Schedule schedule = new Schedule(new ScheduleWidget.ScheduledEvents.Event() { Title = e.title, DaysOfWeekOptions = (DayOfWeekEnum)e.day, FrequencyTypeOptions = (FrequencyTypeEnum)e.frequency, MonthlyIntervalOptions = (MonthlyIntervalEnum)e.monthly_interval }); var occurence = Convert.ToDateTime(schedule.NextOccurrence(DateTime.Now)); evt.Start = new iCalDateTime(new DateTime(occurence.Year, occurence.Month, occurence.Day, e.start.Hour, e.start.Minute, 0)); var attendes = new List<IAttendee>(); if (e.Organisator != null && e.Organisator != 0) { var ms = Services.MemberService; var member = ms.GetById(e.Organisator); string attendee = "MAILTO:" + member.Email; IAttendee reqattendee = new DDay.iCal.Attendee(attendee) { CommonName = member.Name, Role = "REQ-PARTICIPANT" }; attendes.Add(reqattendee); } if (attendes != null && attendes.Count > 0) { evt.Attendees = attendes; } } // Create a serialization context and serializer factory. // These will be used to build the serializer for our object. ISerializationContext ctx = new SerializationContext(); ISerializerFactory factory = new DDay.iCal.Serialization.iCalendar.SerializerFactory(); // Get a serializer for our object IStringSerializer serializer = factory.Build(iCal.GetType(), ctx) as IStringSerializer; string output = serializer.SerializeToString(iCal); var contentType = "text/calendar"; var bytes = Encoding.UTF8.GetBytes(output); return File(bytes, contentType, cal.Calendarname + ".ics"); }
public ActionResult GetEventDetails(int id, int calendar, int type = 0) { EventLocation l = null; EventDetailsModel evm = null; var ms = Services.MemberService; if (type == 0) { //Fetch Event var e = EventService.GetEvent(id); //If it has a location fetch it if (e.locationId != 0) { l = LocationService.GetLocation(e.locationId); } evm = new EventDetailsModel() { CalendarId = calendar, Title = e.title, LocationId = e.locationId, Location = l, Descriptions = e.descriptions }; if (null != e.start) { evm.StartDate = ((DateTime)e.start).ToString("F", CultureInfo.CurrentCulture); } if (null != e.end) { evm.EndDate = ((DateTime)e.end).ToString("F", CultureInfo.CurrentCulture); } if (e.Organisator != null && e.Organisator != 0) { var member = ms.GetById(e.Organisator); evm.Organisator = new Organisator() { Name = member.Name, Email = member.Email }; } } else if (type == 1) { var e = RecurringEventService.GetRecurringEvent(id); if (e.locationId != 0) { l = LocationService.GetLocation(e.locationId); } Schedule schedule = new Schedule(new ScheduleWidget.ScheduledEvents.Event() { Title = e.title, DaysOfWeekOptions = (DayOfWeekEnum)e.day, FrequencyTypeOptions = (FrequencyTypeEnum)e.frequency, MonthlyIntervalOptions = (MonthlyIntervalEnum)e.monthly_interval }); evm = new EventDetailsModel() { CalendarId = calendar, Title = e.title, LocationId = e.locationId, Location = l, Descriptions = e.descriptions }; if (null != e.start) { var start = ((DateTime)schedule.NextOccurrence(DateTime.Now)); evm.StartDate = new DateTime(start.Year, start.Month, start.Day, e.start.Hour, e.start.Minute, 0).ToString("F", CultureInfo.CurrentCulture); } if (null != e.end) { var end = ((DateTime)schedule.NextOccurrence(DateTime.Now)); evm.EndDate = new DateTime(end.Year, end.Month, end.Day, e.end.Hour, e.end.Minute, 0).ToString("F", CultureInfo.CurrentCulture); } if (e.Organisator != null && e.Organisator != 0) { var member = ms.GetById(e.Organisator); evm.Organisator = new Organisator() { Name = member.Name, Email = member.Email }; } } return PartialView("EventDetails", evm); }