Exemple #1
0
        /// <summary>
        /// Create a new web page for content view
        /// </summary>
        /// <param name="view">The content view </param>
        /// <param name="parentId">The parent page id.</param>
        /// <param name="title">The page title</param>
        /// <param name="desc">The page description</param>
        /// <returns>A web page decorator object that wrapps the web page model.</returns>
        public WebPageDecorator CreatePage(ContentViewDecorator view, int parentId = 0, string title = "", string desc = "")
        {
            var slugFormatted = string.Format("lists/{0}/views/{1}", view.Parent.Name, view.Name);
            var locale        = view.Parent.Locale;

            var existingPage = FindPage(locale, slugFormatted);

            if (existingPage != null)
            {
                return(new WebPageDecorator(existingPage, Context));
            }

            var newpage = new WebPage()
            {
                Slug           = slugFormatted,
                IsShared       = false,
                IsStatic       = false,
                Title          = view.IsDefault ? view.Parent.Title : view.Title,
                Description    = view.Description,
                ShowInMenu     = false,
                ShowInSitemap  = true,
                AllowAnonymous = true,
                Created        = DateTime.Now,
                LastModified   = DateTime.Now,
                WebID          = this.Id,
                Owner          = this.Owner,
                Dir            = this.Dir,
                Locale         = locale,
                ParentID       = parentId
            };

            if (!string.IsNullOrEmpty(title))
            {
                newpage.Title = title;
            }

            if (!string.IsNullOrEmpty(desc))
            {
                newpage.Description = desc;
            }

            Context.Add(newpage);
            Context.SaveChanges();
            if (parentId > 0)
            {
                var parentPage = Context.Find <WebPage>(parentId);
                if (parentPage != null)
                {
                    newpage.Path = parentPage.Path + "/" + newpage.ID.ToString();
                    Context.SaveChanges();
                }
            }

            if (string.IsNullOrEmpty(newpage.Path))
            {
                newpage.Path = "0/" + newpage.ID.ToString();
            }

            #region create static widgets
            var app = App.Get();
            var listInfoDescriptor = app.Descriptors[@"content\listinfo"];
            var listInfoWidget     = app.AddWidgetTo(this.Name, newpage.ID, listInfoDescriptor.ID, "ContentZone", 0);
            listInfoWidget.ShowHeader = false;
            listInfoWidget.ShowBorder = false;
            listInfoWidget.Title      = view.Parent.Title;
            listInfoWidget.SetUserPreference("listName", view.Parent.Name);
            listInfoWidget.SetUserPreference("showTitle", false);
            listInfoWidget.SetUserPreference("showTools", true);
            listInfoWidget.Save();

            //create view widget
            var viewDescriptor = app.Descriptors[@"content\dataview"];
            var viewWidget     = app.AddWidgetTo(this.Name, newpage.ID, viewDescriptor.ID, "ContentZone", 1);
            viewWidget.ShowHeader = false;
            viewWidget.ShowBorder = false;
            viewWidget.IsStatic   = true;
            viewWidget.Title      = view.Title;
            viewWidget.SetUserPreference("listName", view.Parent.Name);
            viewWidget.SetUserPreference("viewName", view.Name);
            viewWidget.SetUserPreference("allowFiltering", false);
            viewWidget.SetUserPreference("allowSorting", false);
            viewWidget.SetUserPreference("allowPaging", view.AllowPaging);
            viewWidget.SetUserPreference("pagingInfo", true);
            viewWidget.SetUserPreference("pageIndex", view.PageIndex);
            viewWidget.SetUserPreference("pageSize", view.PageSize);
            viewWidget.Save();

            #endregion

            var pageWrapper = new WebPageDecorator(newpage, Context);
            if (view.Roles != null && view.Roles.Count() > 0)
            {
                pageWrapper.AddRoles(pageWrapper.Roles);
            }

            //Context.SaveChanges();
            pageWrapper.UpdatePositions();
            app.CurrentWeb.ClearCache();
            return(pageWrapper);
        }