示例#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;
        }
示例#2
0
 /// <summary>
 /// Create new widget insance by specified widget data.
 /// </summary>
 /// <param name="widgetTemplate">The widget data.</param>
 /// <param name="dbContext">The data context object.</param>
 /// <param name="parentPage">The web page instanct which contains the new widget.</param>
 /// <returns>A new widget instance created by specified widget data.</returns>
 public static WidgetInstance Install(this IWidget widgetTemplate, IDataContext dbContext, WebPage parentPage)
 {
     return dbContext.Widgets.AddWidget(widgetTemplate, parentPage.ID, string.IsNullOrEmpty(widgetTemplate.ZoneID) ? "zone0" : widgetTemplate.ZoneID, widgetTemplate.Pos);
 }
示例#3
0
        /// <summary>
        /// Create a new web page to current website
        /// </summary>
        /// <param name="title">The page title</param>
        /// <param name="desc">The page description</param>
        /// <param name="keywords">The page keywords</param>
        /// <returns>A web page decorator object that wrapps the web page model.</returns>
        public WebPageDecorator CreatePage(string title, string desc = "", string keywords = "")
        {
            if (string.IsNullOrEmpty(title))
                throw new ArgumentNullException("title");

            var userName = "";
            var ctx = HttpContext.Current;
            if (ctx != null && ctx.User.Identity != null)
            {
                //if (!ctx.Request.IsAuthenticated)
                //  throw new AccessDenyException();
                userName = ctx.User.Identity.Name;
            }
            else
            {
                //Only for test
                userName = this.Owner;
            }

            var page = new WebPage()
            {
                ParentID = 0,
                WebID = Id,
                Created = DateTime.UtcNow,
                LastModified = DateTime.UtcNow,
                Owner = userName,
                AllowAnonymous = true,
                Title = title,
                Description = desc,
                Keywords = keywords,
                ShowInMenu = true,
                ShowInSitemap = true,
                ViewName = ""
            };

            if (string.IsNullOrEmpty(page.Locale))
                page.Locale = this.Culture;

            var slugArgs = Context.WebPages.Filter(p => p.WebID == this.Id && p.Locale == page.Locale).Select(s => s.Slug).ToArray();

            var slug = Utility.TextUtility.Slug(title);
            var counter = 0;
            page.Slug = slug;

            while (slugArgs.Contains(page.Slug))
                page.Slug = slug + (++counter).ToString();

            //page.Path = WebPageDecorator.GeneratePermalink(page, this.Name, Context.WebPages);

            Context.Add(page);
            Context.SaveChanges();
            page.Path = "0/" + page.ID;
            Context.SaveChanges();
            return new WebPageDecorator(page, Context);
        }
示例#4
0
 /// <summary>
 /// Create new widget instance by specified widget descriptor.
 /// </summary>
 /// <param name="descriptor">The widget descriptor object.</param>
 /// <param name="dbContext">The data context object.</param>
 /// <param name="parentPage">The parent web page object.</param>
 /// <param name="zoneID">The zone element id which contains the new widget.</param>
 /// <param name="pos">The position of the new widget.</param>
 /// <returns>A widget instance created by specified widget descriptor.</returns>
 public static WidgetInstance Install(this WidgetDescriptor descriptor, IDataContext dbContext, WebPage parentPage, string zoneID = "zone0", int pos = 0)
 {
     return dbContext.Widgets.AddWidget(descriptor, parentPage.ID, zoneID, pos);
 }