예제 #1
0
        private void PublishAsNew(PageEntity item)
        {
            if (item.ID.IsNullOrWhiteSpace())
            {
                throw new Exception("Can not publish page while it is new.");
            }

            item.IsPublishedPage = true;
            item.PublishDate     = DateTime.Now;
            var zones       = _zoneService.GetByPage(item);
            var layoutHtmls = _layoutHtmlService.GetByPage(item);
            var widgets     = _widgetService.GetByPageId(item.ID);

            Add(item);
            zones.Each(m =>
            {
                m.PageId = item.ID;
                _zoneService.Add(m);
            });
            layoutHtmls.Each(m =>
            {
                m.PageId = item.ID;
                _layoutHtmlService.Add(m);
            });
            widgets.Each(m =>
            {
                using (var widgetService = _widgetActivator.Create(m))
                {
                    m        = widgetService.GetWidget(m);
                    m.PageID = item.ID;
                    widgetService.Publish(m);
                }
            });
        }
예제 #2
0
        public void Publish(PageEntity item)
        {
            _eventManager.Trigger(Events.OnPagePublishing, item);
            string pageId = item.ID;

            BeginTransaction(() =>
            {
                item.IsPublish   = true;
                item.PublishDate = DateTime.Now;
                base.Update(item);

                var zones       = _zoneService.GetByPage(item);
                var layoutHtmls = _layoutHtmlService.GetByPage(item);


                item.ReferencePageID = item.ID;
                item.IsPublishedPage = true;
                item.PublishDate     = DateTime.Now;

                var widgets = _widgetService.GetByPageId(item.ID);
                Add(item);
                zones.Each(m =>
                {
                    m.PageId = item.ID;
                    _zoneService.Add(m);
                });
                layoutHtmls.Each(m =>
                {
                    m.PageId = item.ID;
                    _layoutHtmlService.Add(m);
                });
                widgets.Each(m =>
                {
                    using (var widgetService = _widgetActivator.Create(m))
                    {
                        m        = widgetService.GetWidget(m);
                        m.PageID = item.ID;
                        widgetService.IsNeedNotifyChange = false;
                        widgetService.Publish(m);
                    }
                });
            });
            const int keepVersions        = 6;
            var       allPublishedVersion = Get(m => m.ReferencePageID == pageId && m.IsPublishedPage == true).OrderByDescending(m => m.PublishDate).ToList();

            if (allPublishedVersion.Count > keepVersions)
            {
                for (int i = keepVersions; i < allPublishedVersion.Count; i++)
                {
                    DeleteVersion(allPublishedVersion[i].ID);
                }
            }
            _widgetService.RemoveCache(pageId);
            _zoneService.RemoveCache(pageId);
            _layoutHtmlService.RemoveCache(pageId);
            _eventManager.Trigger(Events.OnPagePublished, item);
        }
예제 #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);
                    });
                }
            }
        }