Beispiel #1
0
        /// <summary>
        /// An item was updated.
        /// </summary>
        public override void ItemUpdated(SPItemEventProperties properties)
        {
            String workBoxURL = properties.ListItem.WBxGetAsString(WBColumn.WorkBoxURL);

            if (!String.IsNullOrEmpty(workBoxURL))
            {
                using (WorkBox workBox = new WorkBox(workBoxURL))
                {
                    workBox.ReferenceDate = (DateTime)properties.ListItem["EventDate"];

                    if (workBox.Item.WBxColumnExists("EventDate"))
                    {
                        workBox.Item["EventDate"] = properties.ListItem["EventDate"];
                    }

                    if (workBox.Item.WBxColumnExists("EndDate"))
                    {
                        workBox.Item["EndDate"] = properties.ListItem["EndDate"];
                    }

                    workBox.GenerateTitle();
                    workBox.Item.Update();
                    workBox.UpdateCachedDetails();

                    workBox.UpdateWorkBoxWebSiteTitle();

                    // Finally we're going to update the title of the calendar event as it may have changed
                    // in light of the update to the title of the associated work box.
                    using (EventsFiringDisabledScope noevents = new EventsFiringDisabledScope())
                    {
                        properties.ListItem["Title"] = workBox.Title;
                        properties.ListItem.Update();
                    }
                }
            }

            base.ItemUpdated(properties);
        }
        protected void saveButton_OnClick(object sender, EventArgs e)
        {
            try
            {
                bool digestOK = WorkBox.Web.ValidateFormDigest();

                if (digestOK)
                {
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        using (SPSite elevatedSite = new SPSite(WorkBox.Site.ID))
                            using (SPWeb elevatedWorkBoxWeb = elevatedSite.OpenWeb(WorkBox.Web.ID))
                            {
                                elevatedSite.AllowUnsafeUpdates       = true;
                                elevatedWorkBoxWeb.AllowUnsafeUpdates = true;

                                WorkBox elevatedWorkBox    = new WorkBox(elevatedSite, elevatedWorkBoxWeb);
                                elevatedWorkBox.ShortTitle = WorkBoxShortTitle.Text;
                                elevatedWorkBox.Web.Title  = WorkBoxPrettyTitle.Text;
                                elevatedWorkBox.GenerateTitle();

                                if (showReferenceID)
                                {
                                    elevatedWorkBox.ReferenceID = ReferenceID.Text;
                                }

                                if (showReferenceDate)
                                {
                                    if (!ReferenceDate.IsDateEmpty)
                                    {
                                        elevatedWorkBox.ReferenceDate = ReferenceDate.SelectedDate;
                                    }
                                }

                                elevatedWorkBox.Update();
                            }
                    });
                }
            }
            catch (Exception exception)
            {
                WBUtils.SendErrorReport(SPContext.Current.Web, "Exception in EditWorkBoxPropertise.saveButton_OnClick()", "Something went wrong when saving: " + exception.Message + " ... " + exception.StackTrace);
                throw new NotImplementedException("Something went wrong when saving the properties changes");
            }

            WBFarm farm = WBFarm.Local;
            String cachedDetailsListUrl = farm.OpenWorkBoxesCachedDetailsListUrl;

            if (!String.IsNullOrEmpty(cachedDetailsListUrl))
            {
                using (SPSite cacheSite = new SPSite(cachedDetailsListUrl))
                    using (SPWeb cacheWeb = cacheSite.OpenWeb())
                    {
                        SPList cacheList = cacheWeb.GetList(cachedDetailsListUrl);

                        SPServiceContext   serviceContext = SPServiceContext.GetContext(cacheSite);
                        UserProfileManager profileManager = new UserProfileManager(serviceContext);

                        // Get the current user's user profile:
                        UserProfile profile = profileManager.GetUserProfile(true);

                        // We're using the 'now' plus one hour ticks as we're not really looking to update the last modified dates of other work boxes.
                        WBUser.CheckLastModifiedDatesAndTitlesOfRecentWorkBoxes(cacheSite, cacheList, profile, DateTime.Now.AddHours(1).Ticks);

                        WBUser.CheckTitlesOfFavouriteWorkBoxes(cacheSite, cacheList, profile);
                    }
            }

            returnFromDialogOK("");
        }