Exemplo n.º 1
0
        protected void Save_OnClick(object sender, EventArgs e)
        {
            if (!canAccessSection)
            {
                return;
            }

            var settings = BaseMapper.GetObjectFromContext(SettingsMapper.GetSettings());

            UpdateObjectFromFields(settings);

            var returnObj = SettingsMapper.Update(settings);

            if (returnObj.IsError)
            {
                DisplayErrorMessage("Error saving settings", returnObj.Error);
            }
            else
            {
                ContextHelper.ClearAllMemoryCache();
                FileCacheHelper.ClearAllCache();

                SettingsMapper.ClearCache();

                DisplaySuccessMessage("Successfully saved settings");
            }
        }
Exemplo n.º 2
0
        protected void PublishNow_OnClick(object sender, EventArgs e)
        {
            if (!CurrentUser.HasPermission(PermissionsEnum.Publish))
            {
                DisplayErrorMessage("Error publishing item", ErrorHelper.CreateError(new Exception("You do not have the appropriate permissions to publish items")));
                return;
            }

            selectedItem = BaseMapper.GetObjectFromContext((MediaDetail)selectedItem);

            if (selectedItem == null)
            {
                return;
            }

            var mediaType = MediaTypesMapper.GetByID(selectedItem.MediaTypeID);

            selectedItem.PublishDate = DateTime.Now;

            if (selectedItem.ExpiryDate != null)
            {
                selectedItem.ExpiryDate = null;
            }

            selectedItem.ShowInMenu          = mediaType.ShowInMenu;
            selectedItem.ShowInSearchResults = mediaType.ShowInSearchResults;
            selectedItem.EnableCaching       = mediaType.EnableCaching;

            Return returnObj = MediaDetailsMapper.Update(selectedItem);

            if (returnObj.IsError)
            {
                DisplayErrorMessage("Error Publishing Item", returnObj.Error);
            }
            else
            {
                DisplaySuccessMessage("Successfully Published Item");

                var mediaId = (selectedItem.Media.ParentMediaID != null) ? selectedItem.Media.ParentMediaID : selectedItem.MediaID;

                ExecuteRawJS("RefreshSiteTreeNodeById(" + mediaId + "); ReloadPreviewPanel();");

                UpdateFieldsFromObject();

                PublishNow.Visible = false;
                ContextHelper.Clear(ContextType.Cache);
                FileCacheHelper.ClearAllCache();
            }

            UpdateFieldsFromObject();

            OnPublishExecuteCode();
        }
Exemplo n.º 3
0
        protected void PublishLive_OnClick(object sender, EventArgs e)
        {
            var returnObj = ((MediaDetail)selectedItem).PublishLive();

            if (!returnObj.IsError)
            {
                ContextHelper.Clear(ContextType.Cache);
                FileCacheHelper.ClearAllCache();

                //if (selectedItem.AbsoluteUrl != liveVersion.AbsoluteUrl)
                //    ChangeLinksForAllMediaDetails(liveVersion.AbsoluteUrl, selectedItem.AbsoluteUrl);

                OnPublishExecuteCode();

                RedirectToAdminUrl(selectedItem);
            }
            else
            {
                DisplayErrorMessage("Error Pushing LIVE", returnObj.Error);
            }
        }
Exemplo n.º 4
0
        //private void ChangeLinksForAllMediaDetails(string oldAbsoluteUrl, string newAbsoluteUrl)
        //{
        //    if (string.IsNullOrEmpty(oldAbsoluteUrl) || oldAbsoluteUrl == newAbsoluteUrl)
        //        return;

        //    var oldTemplateVarUrl = ParserHelper.ParseData(oldAbsoluteUrl, this.TemplateVars, true);
        //    var newTemplateVarUrl = ParserHelper.ParseData(newAbsoluteUrl, this.TemplateVars, true);

        //    var foundItems = MediaDetailsMapper.GetDataModel().MediaDetails.Where(i => i.MainContent.Contains(oldTemplateVarUrl) || i.ShortDescription.Contains(oldTemplateVarUrl));

        //    if (foundItems.Any())
        //    {
        //        foreach (var item in foundItems)
        //        {
        //            item.ShortDescription = item.ShortDescription.Replace(oldTemplateVarUrl, newTemplateVarUrl);
        //            item.MainContent = item.MainContent.Replace(oldTemplateVarUrl, newTemplateVarUrl);
        //        }

        //        var numberOfItemsEffected = MediaDetailsMapper.GetDataModel().SaveChanges();
        //    }
        //}

        protected void Save_OnClick(object sender, EventArgs e)
        {
            if (CanAccessItem != null && CanAccessItem.IsError)
            {
                DisplayErrorMessage("Error saving item", CanAccessItem.Error);
                return;
            }

            if (!CurrentUser.HasPermission(PermissionsEnum.Publish))
            {
                DisplayErrorMessage("Error saving item", ErrorHelper.CreateError(new Exception("You do not have the appropriate permissions to save items")));
                return;
            }

            string commandArgument = ((LinkButton)sender).CommandArgument;

            bool isDraft = false;

            if (commandArgument == "CreateDraft")
            {
                isDraft = true;
            }

            IMediaDetail history = CreateHistory(isDraft);

            Return returnObj = BaseMapper.GenerateReturn();

            if ((history != null) && (history.IsDraft))
            {
                history.CopyFrom(selectedItem);
                UpdateObjectFromFields(history);
                history.IsDraft = isDraft;

                returnObj = SaveHistory(history);

                if (returnObj.IsError)
                {
                    DisplayErrorMessage("Error Saving Item", returnObj.Error);
                }
                else
                {
                    DisplaySuccessMessage("Successfully Saved Item as Draft");

                    UpdateFieldsFromObject();
                }

                RedirectToAdminUrl(selectedItem, history.HistoryVersionNumber);

                return;
            }

            var tmpSelectedItem = BaseMapper.GetObjectFromContext((MediaDetail)selectedItem);

            if (tmpSelectedItem != null)
            {
                selectedItem = tmpSelectedItem;
            }

            if (parentMediaItem != null)
            {
                parentMediaItem = BaseMapper.GetObjectFromContext(parentMediaItem);
            }
            else
            {
                parentMediaItem = selectedItem?.Media?.ParentMedia;
            }

            if (selectedItem == null)
            {
                selectedItem = MediaDetailsMapper.CreateObject(mediaTypeId, selectedMediaItem, parentMediaItem);
            }

            var oldLinkTitle       = selectedItem.LinkTitle;
            var oldVirtualPath     = selectedItem.VirtualPath;
            var canRender          = selectedItem.CanRender;
            var oldAbsoluteUrl     = selectedItem.AbsoluteUrl;
            var oldPostPublishDate = selectedItem.PublishDate;

            UpdateObjectFromFields(selectedItem);

            var validate = selectedItem.Validate();

            if (validate.IsError)
            {
                DisplayErrorMessage("Error saving item", validate.Error);
                return;
            }

            if ((oldPostPublishDate != selectedItem.PublishDate) && !CurrentUser.HasPermission(PermissionsEnum.Publish))
            {
                DisplayErrorMessage("Error saving item", ErrorHelper.CreateError(new Exception("You do not have the appropriate permissions to publish items")));
                return;
            }

            if (selectedItem.ID == 0)
            {
                selectedItem.CreatedByUserID = CurrentUser.ID;

                if ((parentMediaItem != null) && (selectedItem.Media.ID == 0))
                {
                    selectedItem.Media.OrderIndex = parentMediaItem.ChildMedias.Count(i => i.ID != 0);
                }


                returnObj = MediaDetailsMapper.Insert(selectedItem);

                if (!returnObj.IsError)
                {
                    ContextHelper.Clear(ContextType.Cache);
                    FileCacheHelper.ClearAllCache();
                }
                else
                {
                    DisplayErrorMessage("Error", returnObj.Error);
                }
            }
            else
            {
                if (!isDraft)
                {
                    if (history != null)
                    {
                        returnObj = SaveHistory(history);
                    }

                    //selectedItem.Media.ReorderChildren();

                    if (!returnObj.IsError)
                    {
                        returnObj = MediaDetailsMapper.Update(selectedItem);
                    }
                }
            }

            if (returnObj.IsError)
            {
                DisplayErrorMessage("Error Saving Item", returnObj.Error);
            }
            else
            {
                if (history != null)
                {
                    selectedItem.History.Add((MediaDetail)history);
                    Return historyReturnObj = MediaDetailsMapper.Update(selectedItem);
                }

                selectedItem.RemoveFromCache();
                FileCacheHelper.DeleteGenerateNavCache();

                if (oldVirtualPath != selectedItem.VirtualPath || canRender != selectedItem.CanRender || oldLinkTitle != selectedItem.LinkTitle)
                {
                    ContextHelper.Clear(ContextType.Cache);
                    //FileCacheHelper.ClearCacheDir("generatenav");

                    //FileCacheHelper.ClearAllCache();

                    selectedItem.ClearAutoCalculatedVirtualPathCache();

                    if (commandArgument == "SaveAndPublish")
                    {
                        PublishNow_OnClick(sender, e);
                        //RedirectToMediaDetail(mediaTypeEnum, selectedItem.MediaID, selectedItem.Media.ParentMediaID);
                    }
                    else
                    {
                        RedirectToAdminUrl(selectedItem.MediaTypeID, selectedItem.MediaID, selectedItem.Media.ParentMediaID);
                    }

                    //ChangeLinksForAllMediaDetails(oldAbsoluteUrl, selectedItem.AbsoluteUrl);
                }

                DisplaySuccessMessage("Successfully Saved Item");

                ExecuteRawJS("ReloadPreviewPanel()");

                if (!selectedItem.IsHistory)
                {
                    SelectedMediaDetail = selectedItem;
                    SelectedMedia       = MediasMapper.GetByID(selectedItem.MediaID);
                }

                if (((Request["selectedMediaId"] == null) || (Request["selectedMediaId"].ToString() == "0")) && (commandArgument != "SaveAndPublish"))
                {
                    RedirectToAdminUrl(selectedItem.MediaTypeID, selectedItem.MediaID, selectedItem.Media.ParentMediaID);
                }
                else
                {
                    if (commandArgument == "SaveAndPublish")
                    {
                        PublishNow_OnClick(sender, e);
                        //RedirectToMediaDetail(mediaTypeEnum, selectedItem.MediaID, selectedItem.Media.ParentMediaID);
                    }

                    UpdateFieldsFromObject();

                    /*else
                     *  Response.Redirect(Request.Url.AbsoluteUri);*/

                    //UpdateFieldsFromObject();
                    //RedirectToMediaDetail(mediaTypeEnum, selectedItem.MediaID, selectedItem.Media.ParentMediaID);
                }
            }
        }