Ejemplo n.º 1
0
        public static Calendar CreateCourseAppointment(Course course, IIdentity currentUser)
        {
            TimeZoneInfo tzi = course.Department.Institution.TimeZone;
            var currentCal = CreateCal(course);
            // Create the event, and add it to the iCalendar
            //
            Event courseEvt = new Event
            {
                Class = "PRIVATE",
                Created = new CalDateTime(course.CreatedUtc),
                LastModified = new CalDateTime(course.CourseDatesLastModified),
                Sequence = course.EmailSequence,
                Transparency = TransparencyType.Opaque,
                Status = course.Cancelled ? EventStatus.Cancelled : EventStatus.Confirmed,
                Uid = "course" + course.Id.ToString(),
                Priority = 5,
                Location = course.Room.ShortDescription,
                Attendees = course.CourseParticipants.Select(MapCourseParticipantToAttendee).ToList(),
                Summary = course.Department.Abbreviation + " " + course.CourseFormat.CourseType.Abbreviation,
                IsAllDay = false,
                Description = course.Department.Name + " " + course.CourseFormat.CourseType.Description,
                GeographicLocation = GetGeoLocation(course),
                Organizer = GetOrganizer(course),
                //DtStamp = - this is probably being inserted - check
            };
            System.Diagnostics.Debug.WriteLine(courseEvt.Organizer);
            foreach (var cd in course.AllDays().Take(course.CourseFormat.DaysDuration))
            {
                var dayEvt = courseEvt.Copy<Event>();
                dayEvt.Start = new CalDateTime(course.StartLocal, tzi.Id);
                dayEvt.Description += " - " + course.StartLocal.ToString("g");
                dayEvt.Duration = TimeSpan.FromMinutes(cd.DurationMins);
                if (course.CourseFormat.DaysDuration > 1)
                {
                    string dayNo = $" (day {cd.Day})";
                    dayEvt.Summary += dayNo;
                    dayEvt.Description += dayNo;
                }
                currentCal.Events.Add(dayEvt);
            }

            // Create a serialization context and serializer factory.
            // These will be used to build the serializer for our object.

            //set alarm
            Alarm alarm = new Alarm
            {
                Action = AlarmAction.Display,
                Summary = course.Department.Abbreviation + ' ' + course.CourseFormat.CourseType.Abbreviation,
                Trigger = new Trigger(TimeSpan.FromHours(-1))
            };

            // Add the alarm to the event
            courseEvt.Alarms.Add(alarm);

            return currentCal;
        }