public static RecurringEvent CreateEvent(RecurringEvent revent)
        {
            var args = new RecurringEventCreatingEventArgs { RecurringEvent = revent };
            OnCreating(args);

            if (args.Cancel)
            {
                return revent;
            }

            ApplicationContext.Current.DatabaseContext.Database.Save(revent);

            //Create the new descriptions for the new event
            revent.descriptions = DescriptionService.GetDescriptionsForEvent(revent.calendarId, revent.Id, EventType.Normal).ToList();

            var ls = ApplicationContext.Current.Services.LocalizationService;
            foreach (var lang in ls.GetAllLanguages())
            {
                if (revent.descriptions.SingleOrDefault(x => x.CultureCode == lang.CultureInfo.ToString()) == null)
                {
                    revent.descriptions.Add(new EventDescription() { CalendarId = revent.calendarId, EventId = revent.Id, CultureCode = lang.CultureInfo.ToString(), Id = 0, Type = (int)EventType.Recurring });
                }
            }

            var args2 = new RecurringEventCreatedEventArgs { RecurringEvent = revent };
            OnCreated(args2);

            return revent;
        }
Ejemplo n.º 2
0
 private string GetDescription(EventCalendar.Core.Models.RecurringEvent e, string culture)
 {
     if (e.descriptions != null && e.descriptions.Any(x => x.CultureCode == culture))
     {
         return(e.descriptions.SingleOrDefault(x => x.CultureCode == culture).Content);
     }
     else
     {
         return("");
     }
 }
        public static RecurringEvent UpdateEvent(RecurringEvent revent)
        {
            ApplicationContext.Current.DatabaseContext.Database.Update(revent);

            //Save the event descriptions                
            foreach (var desc in revent.descriptions)
            {
                DescriptionService.UpdateDescription(desc);
            }

            return revent;
        }
        public RecurringEvent PostSave(RecurringEvent nevent)
        {
            var ctrl = new DescriptionApiController();

            if (nevent.Id > 0)
            {
                return RecurringEventService.UpdateEvent(nevent);
            }
            else
            {
                return RecurringEventService.CreateEvent(nevent);
            }
        }
        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) });
                    }
                }
            }
        }
        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) });
                    }
                }
            }
        }