Beispiel #1
0
        /// <summary>
        /// Moves the calendar.
        /// </summary>
        /// <param name="calendar">The calendar.</param>
        /// <param name="newFolder">The new folder.</param>
        public static void MoveCalendar(Calendar calendar, CalendarFolder newFolder)
        {
            if (calendar == null)
            {
                throw new ArgumentNullException("calendar");
            }
            if (newFolder == null)
            {
                throw new ArgumentNullException("newFolder");
            }

            using (TransactionScope tran = DataContext.Current.BeginTransaction())
            {
                // Raise Calendar Moving
                RaiseEvent(CalendarMoving, calendar, EventArgs.Empty);

                calendar.CalendarFolderId = newFolder.PrimaryKeyId.Value;
                calendar.Owner            = newFolder.Owner;

                calendar.Save();

                RaiseEvent(CalendarMoved, calendar, EventArgs.Empty);

                tran.Commit();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates the calendar.
        /// </summary>
        /// <param name="folder">The folder.</param>
        /// <param name="name">The name.</param>
        /// <param name="ownerId">The owner id.</param>
        /// <returns></returns>
        public static CalendarInfo CreateCalendar(CalendarFolder folder, string name, int?ownerId)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (folder == null)
            {
                throw new ArgumentNullException("folder");
            }
            if (!folder.GetTreeService().CurrentNode.IsAttached)
            {
                throw new ArgumentException("The folder is dettached from tree.", "folder");
            }

            Calendar newItem = null;

            using (TransactionScope tran = DataContext.Current.BeginTransaction())
            {
                // Step 1. Create New Calendar
                newItem = new Calendar();
                newItem.CalendarFolderId = folder.PrimaryKeyId.Value;
                newItem.Title            = name;
                newItem.Owner            = ownerId;

                // Raise List Creating Event
                RaiseEvent(CalendarCreating, newItem, EventArgs.Empty);

                // Add additional parameters
                newItem.Save();

                // Raise List Created Event
                RaiseEvent(CalendarCreated, newItem, EventArgs.Empty);


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

            return(new CalendarInfo(newItem, null));
        }