Esempio n. 1
0
        /// <summary>
        /// Adds the calendar link.
        /// </summary>
        /// <param name="folder">The folder.</param>
        /// <param name="calendar">The calendar.</param>
        /// <returns></returns>
        public static CalendarInfo AddCalendarLink(CalendarFolder folder, Calendar calendar)
        {
            if (folder == null)
            {
                throw new ArgumentNullException("CalendarFolder");
            }
            if (calendar == null)
            {
                throw new ArgumentNullException("Calendar");
            }

            if (!folder.GetTreeService().CurrentNode.IsAttached)
            {
                throw new ArgumentException("The folder is detached from tree.", "folder");
            }

            //Step 1. Determine for already exist link
            CalendarFolderLink[] links = CalendarFolderLink.List(new FilterElement("CalendarId",
                                                                                   FilterElementType.Equal,
                                                                                   calendar.PrimaryKeyId.Value),
                                                                 new FilterElement("FolderId",
                                                                                   FilterElementType.Equal,
                                                                                   folder.PrimaryKeyId.Value));
            if (links.Length != 0)
            {
                Calendar cal = new Calendar(links[0].CalendarId);
                return(new CalendarInfo(cal, links[0]));
            }

            CalendarFolderLink link = null;

            using (TransactionScope tran = DataContext.Current.BeginTransaction())
            {
                // Step 2. Create New CalendarFolderLink
                link            = new CalendarFolderLink();
                link.CalendarId = calendar.PrimaryKeyId.Value;
                link.FolderId   = folder.PrimaryKeyId.Value;

                // Raise List Creating Event
                RaiseEvent(CalendarLinkCreating, link, EventArgs.Empty);

                // Add additional parameters
                link.Save();

                // Raise List Created Event
                RaiseEvent(CalendarLinkCreated, link, EventArgs.Empty);


                // Step. Commit Transaction Return new list info
                tran.Commit();
            }

            return(new CalendarInfo(calendar, link));
        }
Esempio n. 2
0
        /// <summary>
        /// Deletes the link directly.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        internal static void DeleteLinkDirectly(object sender, EventArgs args)
        {
            Calendar calendar = sender as Calendar;

            if (calendar != null)
            {
                CalendarFolderLink[] links =
                    CalendarFolderLink.List(new FilterElement("CalendarId",
                                                              FilterElementType.Equal,
                                                              calendar.PrimaryKeyId.Value));
                foreach (CalendarFolderLink link in links)
                {
                    link.Delete();
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Lists the specified folder id.
        /// </summary>
        /// <param name="folderId">The folder id.</param>
        /// <returns></returns>
        public static CalendarInfo[] GetCalendars(int folderId)
        {
            List <CalendarInfo> retVal = new List <CalendarInfo>();

            // Load primary list
            Calendar [] calendars = Calendar.List(new FilterElement("CalendarFolderId",
                                                                    FilterElementType.Equal, folderId));

            List <CalendarFolderLink> links = new List <CalendarFolderLink>
                                                  (CalendarFolderLink.List(new FilterElement("FolderId",
                                                                                             FilterElementType.Equal, folderId)));

            //Get primary calendar
            foreach (Calendar calendar in calendars)
            {
                CalendarInfo newItem = new CalendarInfo(calendar, null);

                foreach (CalendarFolderLink link in new List <CalendarFolderLink>(links))
                {
                    //remove duplicate
                    if (link.CalendarId == calendar.PrimaryKeyId.Value)
                    {
                        links.Remove(link);
                    }
                }

                retVal.Add(newItem);
            }
            //Get links
            foreach (CalendarFolderLink link in links)
            {
                Calendar     calendar = new Calendar(link.CalendarId);
                CalendarInfo newItem  = new CalendarInfo(calendar, link);
                retVal.Add(newItem);
            }

            return(retVal.ToArray());
        }