コード例 #1
0
        private void ImportEventsToNewCalendar(IICalendarCollection collection)
        {
            var cctrl = new CalendarApiController();
            var ectrl = new EventApiController();
            var rectrl = new REventApiController();            

            //loop through calendar in collection
            foreach (var cal in collection)
            {
                //Create the new calendar
                string name = "New Imported Calendar";
                if(cal.Properties["X-WR-CALNAME"] != null) {
                    if(!String.IsNullOrEmpty(cal.Properties["X-WR-CALNAME"].Value.ToString())) {
                        name = cal.Properties["X-WR-CALNAME"].Value.ToString();
                    }
                }
                var calendar = cctrl.PostSave(new ECalendar() { Id = 0, Calendarname = name, DisplayOnSite = false, IsGCal = false, GCalFeedUrl = "", ViewMode = "month", Color = "#000000", TextColor = "#FFFFFF" });
                //loop through events in calendar
                foreach (var e in cal.Events)
                {
                    //check if it is an reccuring event
                    if (e.RecurrenceRules.Count > 0)
                    {
                        var revent = new RecurringEvent() { allDay = e.IsAllDay, title = e.Summary, start = e.Start.Date, end = e.Start.Date, calendarId = calendar.Id, categories = String.Join(",", e.Categories), Id = 0 };
                        revent.monthly_interval = (int)MonthlyIntervalEnum.First;
                        RecurrencePattern rp = (RecurrencePattern)e.RecurrenceRules[0];
                        switch (rp.Frequency)
                        {
                            case FrequencyType.Daily:
                                {
                                    revent.frequency = (int)FrequencyTypeEnum.Daily;
                                    break;
                                }
                            case FrequencyType.Monthly:
                                {
                                    revent.frequency = (int)FrequencyTypeEnum.Monthly;
                                    break;
                                }
                            case FrequencyType.Weekly:
                                {
                                    revent.frequency = (int)FrequencyTypeEnum.Weekly;
                                    break;
                                }
                            default:
                                {
                                    revent.frequency = (int)FrequencyTypeEnum.Monthly;
                                    break;
                                }
                        }
                        switch (rp.ByDay[0].DayOfWeek)
                        {
                            case DayOfWeek.Monday:
                                {
                                    revent.day = (int)DayOfWeekEnum.Mon;
                                    break;
                                }
                            case DayOfWeek.Tuesday:
                                {
                                    revent.day = (int)DayOfWeekEnum.Tue;
                                    break;
                                }
                            case DayOfWeek.Wednesday:
                                {
                                    revent.day = (int)DayOfWeekEnum.Wed;
                                    break;
                                }
                            case DayOfWeek.Thursday:
                                {
                                    revent.day = (int)DayOfWeekEnum.Thu;
                                    break;
                                }
                            case DayOfWeek.Friday:
                                {
                                    revent.day = (int)DayOfWeekEnum.Fri;
                                    break;
                                }
                            case DayOfWeek.Saturday:
                                {
                                    revent.day = (int)DayOfWeekEnum.Sat;
                                    break;
                                }
                            case DayOfWeek.Sunday:
                                {
                                    revent.day = (int)DayOfWeekEnum.Sun;
                                    break;
                                }
                        }
                        rectrl.PostSave(revent);
                    }
                    else
                    {
                        ectrl.PostSave(new EventCalendar.Core.Models.Event() { allDay = e.IsAllDay, calendarId = calendar.Id, title = e.Summary, start = e.Start.Date, end = e.End.Date, Id = 0, categories = String.Join(",", e.Categories) });
                    }
                }
            }
        }
コード例 #2
0
        private void ImportEventsIntoExistingCalendar(IICalendarCollection collection, int calendar_id)
        {
            var cctrl = new CalendarApiController();
            var ectrl = new EventApiController();
            var rectrl = new REventApiController();

            //loop through calendar in collection
            foreach (var cal in collection)
            {
                //loop through events in calendar
                foreach (var e in cal.Events)
                {
                    //check if it is an reccuring event
                    if (e.RecurrenceRules.Count > 0)
                    {
                        var revent = new RecurringEvent(){ allDay = e.IsAllDay, title = e.Summary, start = e.Start.Date, end = e.Start.Date, calendarId = calendar_id, categories = String.Join(",", e.Categories), Id = 0};
                        revent.monthly_interval = (int)MonthlyIntervalEnum.First;
                        RecurrencePattern rp = (RecurrencePattern)e.RecurrenceRules[0];
                        switch (rp.Frequency)
                        {
                            case FrequencyType.Daily:
                                {
                                    revent.frequency = (int)FrequencyTypeEnum.Daily;
                                    break;
                                }
                            case FrequencyType.Monthly:
                                {
                                    revent.frequency = (int)FrequencyTypeEnum.Monthly;
                                    break;
                                }
                            case FrequencyType.Weekly:
                                {
                                    revent.frequency = (int)FrequencyTypeEnum.Weekly;
                                    break;
                                }
                            default:
                                {
                                    revent.frequency = (int)FrequencyTypeEnum.Monthly;
                                    break;
                                }
                        }
                        switch(e.Start.DayOfWeek) {
                            case DayOfWeek.Monday: {
                                revent.day = (int)DayOfWeekEnum.Mon;
                                break;
                            }
                            case DayOfWeek.Tuesday:
                                {
                                    revent.day = (int)DayOfWeekEnum.Tue;
                                    break;
                                }
                            case DayOfWeek.Wednesday:
                                {
                                    revent.day = (int)DayOfWeekEnum.Wed;
                                    break;
                                }
                            case DayOfWeek.Thursday:
                                {
                                    revent.day = (int)DayOfWeekEnum.Thu;
                                    break;
                                }
                            case DayOfWeek.Friday:
                                {
                                    revent.day = (int)DayOfWeekEnum.Fri;
                                    break;
                                }
                            case DayOfWeek.Saturday:
                                {
                                    revent.day = (int)DayOfWeekEnum.Sat;
                                    break;
                                }
                            case DayOfWeek.Sunday:
                                {
                                    revent.day = (int)DayOfWeekEnum.Sun;
                                    break;
                                }
                        }
                        rectrl.PostSave(revent);
                    }
                    else
                    {
                        ectrl.PostSave(new EventCalendar.Core.Models.Event() { allDay = e.IsAllDay, calendarId = calendar_id, title = e.Summary, start = e.Start.Date, end = e.End.Date, Id = 0, categories = String.Join(",", e.Categories) });
                    }
                }
            }
        }
コード例 #3
0
        private void ImportEventsIntoExistingCalendar(IICalendarCollection collection, int calendar_id)
        {
            var cctrl  = new CalendarApiController();
            var ectrl  = new EventApiController();
            var rectrl = new REventApiController();

            //loop through calendar in collection
            foreach (var cal in collection)
            {
                //loop through events in calendar
                foreach (var e in cal.Events)
                {
                    //check if it is an reccuring event
                    if (e.RecurrenceRules.Count > 0)
                    {
                        var revent = new RecurringEvent()
                        {
                            allDay = e.IsAllDay, title = e.Summary, start = e.Start.Date, end = e.Start.Date, calendarId = calendar_id, categories = String.Join(",", e.Categories), Id = 0
                        };
                        revent.monthly_interval = (int)MonthlyIntervalEnum.First;
                        RecurrencePattern rp = (RecurrencePattern)e.RecurrenceRules[0];
                        switch (rp.Frequency)
                        {
                        case FrequencyType.Daily:
                        {
                            revent.frequency = (int)FrequencyTypeEnum.Daily;
                            break;
                        }

                        case FrequencyType.Monthly:
                        {
                            revent.frequency = (int)FrequencyTypeEnum.Monthly;
                            break;
                        }

                        case FrequencyType.Weekly:
                        {
                            revent.frequency = (int)FrequencyTypeEnum.Weekly;
                            break;
                        }

                        default:
                        {
                            revent.frequency = (int)FrequencyTypeEnum.Monthly;
                            break;
                        }
                        }
                        switch (e.Start.DayOfWeek)
                        {
                        case DayOfWeek.Monday: {
                            revent.day = (int)DayOfWeekEnum.Mon;
                            break;
                        }

                        case DayOfWeek.Tuesday:
                        {
                            revent.day = (int)DayOfWeekEnum.Tue;
                            break;
                        }

                        case DayOfWeek.Wednesday:
                        {
                            revent.day = (int)DayOfWeekEnum.Wed;
                            break;
                        }

                        case DayOfWeek.Thursday:
                        {
                            revent.day = (int)DayOfWeekEnum.Thu;
                            break;
                        }

                        case DayOfWeek.Friday:
                        {
                            revent.day = (int)DayOfWeekEnum.Fri;
                            break;
                        }

                        case DayOfWeek.Saturday:
                        {
                            revent.day = (int)DayOfWeekEnum.Sat;
                            break;
                        }

                        case DayOfWeek.Sunday:
                        {
                            revent.day = (int)DayOfWeekEnum.Sun;
                            break;
                        }
                        }
                        rectrl.PostSave(revent);
                    }
                    else
                    {
                        ectrl.PostSave(new EventCalendar.Core.Models.Event()
                        {
                            allDay = e.IsAllDay, calendarId = calendar_id, title = e.Summary, start = e.Start.Date, end = e.End.Date, Id = 0, categories = String.Join(",", e.Categories)
                        });
                    }
                }
            }
        }
コード例 #4
0
        private void ImportEventsToNewCalendar(IICalendarCollection collection)
        {
            var cctrl  = new CalendarApiController();
            var ectrl  = new EventApiController();
            var rectrl = new REventApiController();

            //loop through calendar in collection
            foreach (var cal in collection)
            {
                //Create the new calendar
                string name = "New Imported Calendar";
                if (cal.Properties["X-WR-CALNAME"] != null)
                {
                    if (!String.IsNullOrEmpty(cal.Properties["X-WR-CALNAME"].Value.ToString()))
                    {
                        name = cal.Properties["X-WR-CALNAME"].Value.ToString();
                    }
                }
                var calendar = cctrl.PostSave(new ECalendar()
                {
                    Id = 0, Calendarname = name, DisplayOnSite = false, IsGCal = false, GCalFeedUrl = "", ViewMode = "month", Color = "#000000", TextColor = "#FFFFFF"
                });
                //loop through events in calendar
                foreach (var e in cal.Events)
                {
                    //check if it is an reccuring event
                    if (e.RecurrenceRules.Count > 0)
                    {
                        var revent = new RecurringEvent()
                        {
                            allDay = e.IsAllDay, title = e.Summary, start = e.Start.Date, end = e.Start.Date, calendarId = calendar.Id, categories = String.Join(",", e.Categories), Id = 0
                        };
                        revent.monthly_interval = (int)MonthlyIntervalEnum.First;
                        RecurrencePattern rp = (RecurrencePattern)e.RecurrenceRules[0];
                        switch (rp.Frequency)
                        {
                        case FrequencyType.Daily:
                        {
                            revent.frequency = (int)FrequencyTypeEnum.Daily;
                            break;
                        }

                        case FrequencyType.Monthly:
                        {
                            revent.frequency = (int)FrequencyTypeEnum.Monthly;
                            break;
                        }

                        case FrequencyType.Weekly:
                        {
                            revent.frequency = (int)FrequencyTypeEnum.Weekly;
                            break;
                        }

                        default:
                        {
                            revent.frequency = (int)FrequencyTypeEnum.Monthly;
                            break;
                        }
                        }
                        switch (rp.ByDay[0].DayOfWeek)
                        {
                        case DayOfWeek.Monday:
                        {
                            revent.day = (int)DayOfWeekEnum.Mon;
                            break;
                        }

                        case DayOfWeek.Tuesday:
                        {
                            revent.day = (int)DayOfWeekEnum.Tue;
                            break;
                        }

                        case DayOfWeek.Wednesday:
                        {
                            revent.day = (int)DayOfWeekEnum.Wed;
                            break;
                        }

                        case DayOfWeek.Thursday:
                        {
                            revent.day = (int)DayOfWeekEnum.Thu;
                            break;
                        }

                        case DayOfWeek.Friday:
                        {
                            revent.day = (int)DayOfWeekEnum.Fri;
                            break;
                        }

                        case DayOfWeek.Saturday:
                        {
                            revent.day = (int)DayOfWeekEnum.Sat;
                            break;
                        }

                        case DayOfWeek.Sunday:
                        {
                            revent.day = (int)DayOfWeekEnum.Sun;
                            break;
                        }
                        }
                        rectrl.PostSave(revent);
                    }
                    else
                    {
                        ectrl.PostSave(new EventCalendar.Core.Models.Event()
                        {
                            allDay = e.IsAllDay, calendarId = calendar.Id, title = e.Summary, start = e.Start.Date, end = e.End.Date, Id = 0, categories = String.Join(",", e.Categories)
                        });
                    }
                }
            }
        }
コード例 #5
0
        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"));
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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");
        }