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);
        }
Beispiel #2
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"));
        }
        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");
        }