|
using System; |
|
using Telerik.Sitefinity.Events.Model; |
|
using Telerik.Sitefinity.Modules.Events; |
|
using Telerik.Sitefinity.RecurrentRules; |
|
|
|
namespace SitefinityWebApp |
|
{ |
|
public class CreateAllDayRecurrentEvents |
|
{ |
|
public static void CreateRecurrentAllDayEvent() |
|
{ |
|
/// Creates a date in UTC (Coordinated Universal Time) format |
|
var startDate = new DateTime(2015, 11, 1, 0, 0, 0, DateTimeKind.Utc); |
|
|
|
/// Creates end date which is 10 days after the start event date. |
|
var endDate = startDate.AddDays(10); |
|
|
|
///Gets an instance of the events manager. |
|
EventsManager manager = EventsManager.GetManager(); |
|
|
|
Guid id = Guid.NewGuid(); |
|
|
|
/// Set timezone id. |
|
string utcTimezoneId = "UTC"; |
|
|
|
/// Creates a new event with the given identity |
|
Event recurrentEvent = manager.CreateEvent(id); |
|
|
|
///Set Title (name) of the content item |
|
recurrentEvent.Title = "Recurrent all day event"; |
|
|
|
///Sets the description of this content. |
|
recurrentEvent.Description = "Recurrent all day event description"; |
|
|
|
///Sets the event content |
|
recurrentEvent.Content = "Recurrent all day event content"; |
|
|
|
///Sets the start date/time of the event in UTC. |
|
recurrentEvent.EventStart = startDate; |
|
|
|
///Sets the end date/time of the event in UTC. |
|
recurrentEvent.EventEnd = endDate; |
|
|
|
///Sets whether the event contains any recurrence logic. |
|
recurrentEvent.IsRecurrent = true; |
|
|
|
///Sets whether the event is all day event. |
|
recurrentEvent.AllDayEvent = true; |
|
|
|
///Sets the location of the current event. |
|
recurrentEvent.Location = "Recurrent all day event location"; |
|
|
|
///Sets the time zone id associated with the event |
|
///This property is used for persisting the timezone chosen when creating an Event. |
|
///The value of this property is important for recurrent events because it is |
|
///used in recurrence expressions and DST as well. |
|
///The TimeZoneId is a key string that uniquely identifies a particular time zone. |
|
recurrentEvent.TimeZoneId = utcTimezoneId; |
|
|
|
/// Defines methods for interacting/creating recurrence rules. |
|
var rrBuilder = new RecurrenceRuleBuilder(); |
|
|
|
/// Creates an expression for a recurrent all day event with one day duration and 10 days occurrences. |
|
var recurrentExpression = rrBuilder.CreateDailyRecurrenceExpression(startDate, TimeSpan.FromDays(1), endDate, 10, 1, utcTimezoneId); |
|
|
|
///Sets the recurrence expression associated with the event. |
|
recurrentEvent.RecurrenceExpression = recurrentExpression; |
|
|
|
/// Publishes the defined event. |
|
manager.Lifecycle.Publish(recurrentEvent); |
|
|
|
/// Save the changes made to events retrieved with this manager. |
|
manager.SaveChanges(); |
|
} |
|
} |
|
} |