Exemple #1
0
        public void Revert(string ID, bool RetainLatest)
        {
            BeginTransaction(() =>
            {
                var page = Get(ID);
                if (page.IsPublishedPage)
                {
                    var refPage       = Get(page.ReferencePageID);
                    refPage.IsPublish = false;
                    Update(refPage);
                    page.Description = "从 {0:yyyy/MM/dd H:mm} 版本撤回".FormatWith(page.PublishDate);
                    page.PublishDate = DateTime.Now;
                    Add(page);

                    var widgets = _widgetService.GetByPageId(ID);
                    widgets.Each(m =>
                    {
                        var widgetService = _widgetActivator.Create(m);
                        m        = widgetService.GetWidget(m);
                        m.PageID = page.ID;
                        widgetService.IsNeedNotifyChange = false;
                        widgetService.Publish(m);
                    });
                    _widgetService.RemoveCache(page.ReferencePageID);
                    if (!RetainLatest)
                    {//清空当前的所有修改
                        _layoutHtmlService.Remove(m => m.PageId == page.ReferencePageID);
                        _zoneService.Remove(m => m.PageId == page.ReferencePageID);
                        _layoutHtmlService.GetByPage(page).Each(m =>
                        {
                            _layoutHtmlService.Add(new LayoutHtml {
                                LayoutId = m.LayoutId, Html = m.Html, PageId = page.ReferencePageID
                            });
                        });
                        _zoneService.GetByPage(page).Each(m =>
                        {
                            m.PageId = page.ReferencePageID;
                            _zoneService.Add(m);
                        });
                        _widgetService.GetByPageId(page.ReferencePageID).Each(m =>
                        {
                            var widgetService = _widgetActivator.Create(m);
                            widgetService.IsNeedNotifyChange = false;
                            widgetService.DeleteWidget(m.ID);
                        });
                        _widgetService.GetByPageId(ID).Each(m =>
                        {
                            var widgetService = _widgetActivator.Create(m);
                            m        = widgetService.GetWidget(m);
                            m.PageID = page.ReferencePageID;
                            widgetService.IsNeedNotifyChange = false;
                            widgetService.Publish(m);
                        });
                    }

                    _zoneService.RemoveCache(page.ReferencePageID);
                    _layoutHtmlService.RemoveCache(page.ReferencePageID);
                }
            });
        }
Exemple #2
0
        public void Revert(string ID, bool RetainLatest)
        {
            var page = Get(ID);

            BeginTransaction(() =>
            {
                if (page.IsPublishedPage)
                {
                    var refPage       = Get(page.ReferencePageID);
                    refPage.IsPublish = false;
                    Update(refPage);
                    page.Description = _localize.Get("Revert from version: {0:g}").FormatWith(page.PublishDate);
                    PublishAsNew(page);
                    if (!RetainLatest)
                    {//清空当前的所有修改
                        _layoutHtmlService.Remove(m => m.PageId == page.ReferencePageID);
                        _zoneService.Remove(m => m.PageId == page.ReferencePageID);
                        _layoutHtmlService.GetByPage(page).Each(m =>
                        {
                            _layoutHtmlService.Add(new LayoutHtml {
                                LayoutId = m.LayoutId, Html = m.Html, PageId = page.ReferencePageID
                            });
                        });
                        _zoneService.GetByPage(page).Each(m =>
                        {
                            m.PageId = page.ReferencePageID;
                            _zoneService.Add(m);
                        });
                        _widgetService.GetByPageId(page.ReferencePageID).Each(m =>
                        {
                            var widgetService = _widgetActivator.Create(m);
                            widgetService.DeleteWidget(m.ID);
                        });
                        _widgetService.GetByPageId(ID).Each(m =>
                        {
                            var widgetService = _widgetActivator.Create(m);
                            m        = widgetService.GetWidget(m);
                            m.PageID = page.ReferencePageID;
                            widgetService.Publish(m);
                        });
                    }
                }
            });
            _eventManager.Trigger(Events.OnPagePublished, page);
        }
Exemple #3
0
        public void UpdateDesign(LayoutEntity item)
        {
            if (item.Page != null && item.Page.ID.IsNotNullAndWhiteSpace())
            {
                if (item.Zones != null)
                {
                    var zones = _zoneService.GetByPage(new PageEntity {
                        ID = item.Page.ID, LayoutId = item.ID
                    });

                    item.Zones.Where(m => zones.All(n => n.ID != m.ID)).Each(m =>
                    {
                        m.LayoutId = item.ID;
                        m.PageId   = item.Page.ID;
                        _zoneService.Add(m);
                    });
                    zones.Each(m =>
                    {
                        var changeZone = item.Zones.FirstOrDefault(z => z.ID == m.ID);
                        if (changeZone != null)
                        {
                            m.LayoutId = item.ID;
                            m.PageId   = item.Page.ID;
                            m.Title    = changeZone.Title;
                            m.ZoneName = changeZone.ZoneName;
                            _zoneService.Update(m);
                        }
                    });
                    zones.Where(m => item.Zones.All(n => n.ID != m.ID)).Each(m => _zoneService.Remove(m.ID));
                }
                if (item.Html != null)
                {
                    _layoutHtmlService.Remove(m => m.PageId == item.Page.ID);
                    item.Html.Each(m =>
                    {
                        m.LayoutId = item.ID;
                        m.PageId   = item.Page.ID;
                        _layoutHtmlService.Add(m);
                    });
                }
            }
            else
            {
                if (item.Zones != null)
                {
                    var zones = _zoneService.Get(m => m.LayoutId == item.ID);

                    item.Zones.Where(m => zones.All(n => n.ID != m.ID)).Each(m =>
                    {
                        m.LayoutId = item.ID;
                        _zoneService.Add(m);
                    });
                    zones.Each(m =>
                    {
                        var changeZone = item.Zones.FirstOrDefault(z => z.ID == m.ID);
                        if (changeZone != null)
                        {
                            m.LayoutId = item.ID;
                            m.Title    = changeZone.Title;
                            m.ZoneName = changeZone.ZoneName;
                            _zoneService.Update(m);
                        }
                    });
                    zones.Where(m => item.Zones.All(n => n.ID != m.ID)).Each(m => _zoneService.Remove(m.ID));
                }
                if (item.Html != null)
                {
                    _layoutHtmlService.Remove(m => m.LayoutId == item.ID);
                    item.Html.Each(m =>
                    {
                        m.LayoutId = item.ID;
                        _layoutHtmlService.Add(m);
                    });
                }
            }
        }