Beispiel #1
0
        public static string SaveAsView(ContentListDecorator list, string template, string fileName,bool overwrite=false)
        {
            var netdrive = App.Get().NetDrive;
            var webName = list.Web.Name;
            var listPath = list.DefaultListPath.ToString();
            var dataPath = netdrive.MapPath(new Uri(listPath + "tmpls/"));

            if (!Directory.Exists(dataPath))
                Directory.CreateDirectory(dataPath);

            if (!File.Exists(dataPath + "web.config"))
            {
                var xdoc = XElement.Load(HttpContext.Current.Server.MapPath("~/views/web.config"));
                xdoc.Save(dataPath + "web.config");
            }

            var fullName = netdrive.MapPath(new Uri(string.Format(listPath + "tmpls/{0}", fileName)));

            if (!File.Exists(fullName) || overwrite)
                File.WriteAllText(fullName, template);

            if (list.Web.Name.Equals("home"))
                return string.Format("~/app_data/files/public/lists/{0}/tmpls/{1}",list.ID, fileName);
            else
                return string.Format("~/app_data/files/personal/{0}/lists/{1}/tmpls/{2}", webName, list.ID, fileName);
        }
        /// <summary>
        /// Render an items tree for specified list
        /// </summary>
        /// <param name="list">The content list object</param>
        /// <param name="current">The content data item object.</param>
        /// <param name="htmlAttributes">The html attributes object.</param>
        /// <returns></returns>
        public static HelperResult Tree(ContentListDecorator list, ContentDataItemDecorator current = null, object htmlAttributes = null)
        {
            return(new HelperResult((w) =>
            {
                using (var writer = new Html32TextWriter(w))
                {
                    writer.WriteBeginTag("ul");
                    writer.WriteAttribute("data-role", "tree");
                    if (htmlAttributes != null)
                    {
                        var dict = htmlAttributes.ToDictionary();
                        foreach (var key in dict.Keys)
                        {
                            if (key.StartsWith("data_"))
                            {
                                writer.WriteAttribute(key.Replace("_", "-"), (string)dict[key]);
                            }
                            else
                            {
                                writer.WriteAttribute(key, (string)dict[key]);
                            }
                        }
                    }

                    writer.Write(Html32TextWriter.TagRightChar);
                    var items = list.GetItems(i => i.ParentItemID == Guid.Empty && i.IsPublished && i.IsCurrentVersion).OrderBy(i => i.Pos);
                    RenderChildren(writer, list, items, current);
                    writer.WriteEndTag("ul");
                }
            }));
        }
Beispiel #3
0
        public static string SaveAsView(ContentListDecorator list, string template, string fileName, bool overwrite = false)
        {
            var netdrive = App.Get().NetDrive;
            var webName  = list.Web.Name;
            var listPath = list.DefaultListPath.ToString();
            var dataPath = netdrive.MapPath(new Uri(listPath + "tmpls/"));

            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }

            if (!File.Exists(dataPath + "web.config"))
            {
                var xdoc = XElement.Load(HttpContext.Current.Server.MapPath("~/views/web.config"));
                xdoc.Save(dataPath + "web.config");
            }

            var fullName = netdrive.MapPath(new Uri(string.Format(listPath + "tmpls/{0}", fileName)));

            if (!File.Exists(fullName) || overwrite)
            {
                File.WriteAllText(fullName, template);
            }

            if (list.Web.Name.Equals("home"))
            {
                return(string.Format("~/app_data/files/public/lists/{0}/tmpls/{1}", list.ID, fileName));
            }
            else
            {
                return(string.Format("~/app_data/files/personal/{0}/lists/{1}/tmpls/{2}", webName, list.ID, fileName));
            }
        }
Beispiel #4
0
        /// <summary>
        /// Converts the content list defautl view virtual (relative) path to an application absolute path.
        /// </summary>
        /// <param name="helper">The url helper object.</param>
        /// <param name="list">The content list object</param>
        /// <returns>A string that contains default view absolute url of the specified content list object.</returns>
        public static string Content(this UrlHelper helper, ContentListDecorator list)
        {
            if (list == null)
                throw new ArgumentNullException("list");

            if (!string.IsNullOrEmpty(list.DefaultUrl))
                return helper.Content(list.DefaultUrl);
            return "javascript:void(0);";
        }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the ContentDataItemDecorator class with xml data item element, content list object and data context.
 /// </summary>
 /// <param name="element">The XElement that contains dataitem object data.</param>
 /// <param name="parent">The parent list decorator object.</param>
 /// <param name="context">The data context.</param>
 public ContentDataItemDecorator(XElement element, ContentListDecorator parent, IDataContext context)
 {
     this.Model = new ContentDataItem()
     {
         ID = Guid.NewGuid(), ParentID = parent.ID
     };
     this.Parent = parent;
     Context     = context;
     this.Load(element);
     flag = true;
 }
 /// <summary>
 /// Initializes a new instance of the ContentFieldRef class.
 /// </summary>
 /// <param name="parent">The parent view object.</param>
 /// <param name="field">The content field.</param>
 public ContentFieldRef(ContentViewDecorator parent, ContentField field)
 {
     this.ParentView = parent;
     this.Parent     = parent.Parent;
     field.CopyTo(this, "Parent");
     isFilterable = field.IsFilterable;
     this.Field   = field;
     Template     = new ContentTemplate();
     if (field.HasViewTemplate)
     {
         Template.Source = field.ViewTemplate;
     }
 }
Beispiel #7
0
        /// <summary>
        /// Converts the content list defautl view virtual (relative) path to an application absolute path.
        /// </summary>
        /// <param name="helper">The url helper object.</param>
        /// <param name="list">The content list object</param>
        /// <returns>A string that contains default view absolute url of the specified content list object.</returns>
        public static string Content(this UrlHelper helper, ContentListDecorator list)
        {
            if (list == null)
            {
                throw new ArgumentNullException("list");
            }

            if (!string.IsNullOrEmpty(list.DefaultUrl))
            {
                return(helper.Content(list.DefaultUrl));
            }
            return("javascript:void(0);");
        }
        private static void RenderChildren(Html32TextWriter writer, ContentListDecorator list, IEnumerable<ContentDataItem> items, ContentDataItem current)
        {
            var app = App.Get();
            var fieldName = list.GetDefaultTitleField().Name;
            var Url = DNA.Utility.UrlUtility.CreateUrlHelper();
            foreach (var item in items)
            {
                var itemWrapper = app.Wrap(item);
                writer.WriteBeginTag("li");
                var _class = "d-node";
                var children = itemWrapper.Children();
                var childrenCount = children.Count();
                if (childrenCount > 0)
                    _class += " d-node-hasChildren";

                //writer.WriteAttribute("class", "d-node d-node-hasChildren");

                var isInPath = false;
                if (current != null && !string.IsNullOrEmpty(current.Path) && !string.IsNullOrEmpty(item.Path) && current.Path.StartsWith(item.Path))
                {
                    isInPath = true;
                    if (childrenCount > 0)
                        writer.WriteAttribute("data-expanded", "true");

                }
                writer.WriteAttribute("data-id", itemWrapper.ID.ToString());

                if (current != null && itemWrapper.ID.Equals(current.ID))
                    writer.WriteAttribute("data-selected", "true");

                if (itemWrapper.ParentItemID != Guid.Empty)
                    writer.WriteAttribute("data-parentid", itemWrapper.ParentItemID.ToString());

                if (childrenCount > 0)
                {
                    if (!isInPath)
                    {
                        var urlformat = "~/api/contents/items?name={0}&slug={1}&parentId={2}";
                        var popupUrl = Url.Content(string.Format(urlformat, list.Name, list.Views.Default.Name, itemWrapper.ID.ToString()));
                        writer.WriteAttribute("data-popupurl", popupUrl);
                    }
                }
                writer.WriteAttribute("class", _class);
                writer.Write(Html32TextWriter.TagRightChar);

                writer.WriteBeginTag("a");
                writer.WriteAttribute("href", itemWrapper.UrlComponent);
                writer.Write(Html32TextWriter.TagRightChar);
                writer.Write(itemWrapper.Value(fieldName).Raw);
                writer.WriteEndTag("a");

                if (childrenCount > 0)
                {
                    if (isInPath)
                    {
                        writer.WriteFullBeginTag("ul");
                        RenderChildren(writer, list, children, current);
                        writer.WriteEndTag("ul");
                    }
                }

                writer.WriteEndTag("li");
            }
        }
Beispiel #9
0
 internal PersonalListHelper(ContentListDecorator parent)
 {
     this._parent = parent;
 }
Beispiel #10
0
 /// <summary>
 /// Trigger an event
 /// </summary>
 /// <param name="ctrl">The content list object.</param>
 /// <param name="eventName">The event name.</param>
 /// <param name="eventArg">The event argument object.</param>
 public static void Trigger(this ContentListDecorator list, string eventName, object eventArg = null)
 {
     App.Trigger(eventName, list, eventArg);
 }
Beispiel #11
0
        /// <summary>
        /// Render a HTML button that use to show the new form for specified content list object.
        /// </summary>
        /// <param name="html">The html helper object.</param>
        /// <param name="list">The content list object.</param>
        /// <returns></returns>
        public static HelperResult NewItemDialogButton(this HtmlHelper html, ContentListDecorator list)
        {
            return new HelperResult(writer =>
            {
                var newForm = list.NewForm;
                if (newForm == null) return;

                var Url = new UrlHelper(html.ViewContext.RequestContext);
                var addNewUrl = UrlBuilder.Create(Url.Content(list.GetNewItemUrl())).AddParam("locale", list.Locale).ToString();

                var xEle = new XElement("a", string.IsNullOrEmpty(newForm.Title) ? HttpContext.GetGlobalResourceObject("Contents", "AddItem").ToString() : newForm.Title,
                    new XAttribute("data-role", "button"),
                    new XAttribute("data-rel", "dialog"),
                    new XAttribute("data-default", "true"),
                    new XAttribute("data-dialog-title", newForm.Title),
                    new XAttribute("data-dialog-cache", "false"),
                    new XAttribute("data-dialog-modal", "true"),
                    new XAttribute("data-dialog-fullscreen", "true"),
                    new XAttribute("href", addNewUrl));

                writer.Write(xEle.OuterXml());
            });
        }
Beispiel #12
0
        private static void RenderColPattern(XElement element, TextWriter w, ContentListDecorator list)
        {
            var prop = element.StrAttr("prop");
            var name = element.StrAttr("name");
            if (!string.IsNullOrEmpty(prop) && !string.IsNullOrEmpty(name))
            {
                var field = list.Fields[name];
                if (field != null)
                {
                    if (prop.Equals("title") && !string.IsNullOrEmpty(field.Title))
                    {
                        w.Write(field.Title);
                        return;
                    }

                    if (prop.Equals("description") && !string.IsNullOrEmpty(field.Description))
                    {
                        w.Write(field.Description);
                        return;
                    }
                }
            }
        }
Beispiel #13
0
        /// <summary>
        /// Create a new content list by specified content type.
        /// </summary>
        /// <param name="contentType">The content type object.</param>
        /// <param name="title">The content list title</param>
        /// <param name="name">The new content list name.</param>
        /// <returns>A content list object</returns>
        public ContentListDecorator CreateList(ContentList contentType, string title, string name)
        {
            var listNames = Lists.Select(l => l.Name).ToArray();

            if (contentType.IsSingle)
            {
                if (Context.Count<ContentList>(c => c.Name.Equals(contentType.BaseType)) > 0)
                    throw new Exception("ContentType already created.");
            }

            if (!string.IsNullOrEmpty(title))
            {
                contentType.Title = title;
                if (string.IsNullOrEmpty(name))
                    contentType.Name = TextUtility.Slug(title);
            }

            if (!string.IsNullOrEmpty(name))
                contentType.Name = TextUtility.Slug(name);

            contentType.WebID = this.Id;
            contentType.Locale = this.Culture;
            contentType.Owner = this.Owner;
            contentType.LastModified = DateTime.Now;
            var uniqueName = contentType.Name;
            var i = 0;

            while (listNames.Contains(uniqueName))
                uniqueName = contentType.Name + (++i).ToString();

            if (uniqueName != contentType.Name)
                contentType.Name = uniqueName;

            var Url = DNA.Utility.UrlUtility.CreateUrlHelper();
            var names = new List<string>();

            //        if (v.StartupScripts != null && !string.IsNullOrEmpty(v.StartupScripts.Source))
            //            view.StartupScripts = string.Format("<script type=\"text/javascript\" src=\"{0}\"></script>", Url.Content(pkg.ResolveUri(v.StartupScripts.Source, v.StartupScripts.Language.Equals(contentType.DefaultLocale, StringComparison.OrdinalIgnoreCase) ? "" : lang)));

            //        if (v.StyleSheet != null && !string.IsNullOrEmpty(v.StyleSheet.Source))
            //            view.StyleSheet = string.Format("<link type=\"text/css\" rel=\"StyleSheet\" href=\"{0}\"></script>", Url.Content(pkg.ResolveUri(v.StyleSheet.Source, v.StyleSheet.Language.Equals(contentType.DefaultLocale, StringComparison.OrdinalIgnoreCase) ? "" : lang)));

            #region unqurie slug
            if (contentType.Views != null)
            {
                foreach (var v in contentType.Views)
                {
                    var slug = v.Name;
                    var flex = slug;
                    var j = 0;
                    while (names.Contains(slug))
                        slug = flex + (++j).ToString();
                    names.Add(slug);

                    if (v.Name != slug)
                        v.Name = slug;
                }

                if (contentType.Views.Count(v => v.IsDefault) == 0)
                    contentType.Views.FirstOrDefault().IsDefault = true;
            }
            #endregion

            if (contentType.Items != null)
            {
                foreach (var dataItem in contentType.Items)
                {
                    if (dataItem.ID == Guid.Empty || Context.Find<ContentDataItem>(dataItem.ID) != null)
                        dataItem.ID = Guid.NewGuid();

                    dataItem.Locale = this.Culture;
                    if (string.IsNullOrEmpty(dataItem.Owner))
                        dataItem.Owner = this.Owner;
                }
            }

            Context.Add(contentType);
            Context.SaveChanges();
            var defaultViewPageID = 0;

            if (contentType.Views != null)
            {
                foreach (var v in contentType.Views)
                {
                    #region new page

                    if (!v.NoPage)
                    {
                        var newpage = CreatePage(new ContentViewDecorator(v, Context), defaultViewPageID);
                        if (newpage == null)
                            continue;

                        if (v.IsDefault)
                            defaultViewPageID = newpage.ID;
                    }

                    #endregion

                    Context.SaveChanges();
                }
            }
            var returns = new ContentListDecorator(Context, contentType);
            returns.ClearCache();
            return returns;
        }
        public ContentListDecorator InstantiateIn(string baseName, string title = "", string listName = "", string webName = "home", string culture = "", bool showInMenu = false)
        {
            var pkg = Packages[baseName];

            if (pkg == null)
            {
                return(null);
            }
            var app  = App.Get();
            var web  = DataContext.Find <Web>(w => w.Name.Equals(webName, StringComparison.OrdinalIgnoreCase));
            var lang = string.IsNullOrEmpty(web.DefaultLocale) ? App.Settings.DefaultLocale : web.DefaultLocale.ToLower();

            if (!string.IsNullOrEmpty(culture))
            {
                lang = culture.ToLower();
            }

            var contentType = pkg.Locale(lang);
            var listNames   = web.Lists.Select(l => l.Name).ToArray();

            if (contentType.IsSingle)
            {
                if (DataContext.Count <ContentList>(c => c.Name.Equals(pkg.Name)) > 0)
                {
                    throw new Exception("ContentType already created.");
                }
            }

            if (string.IsNullOrEmpty(contentType.Name))
            {
                contentType.Name = pkg.Name;
            }

            if (!string.IsNullOrEmpty(title))
            {
                contentType.Title = title;
                if (string.IsNullOrEmpty(listName))
                {
                    contentType.Name = TextUtility.Slug(title);
                }
            }

            if (!string.IsNullOrEmpty(listName))
            {
                contentType.Name = TextUtility.Slug(listName);
            }

            contentType.WebID        = web.Id;
            contentType.BaseType     = pkg.Name;
            contentType.Owner        = web.Owner;
            contentType.LastModified = DateTime.Now;

            //if (!string.IsNullOrEmpty(title))
            //contentType.Name = TextUtility.Slug(title);

            var uniqueName = contentType.Name;
            var i          = 0;

            while (listNames.Contains(uniqueName))
            {
                uniqueName = contentType.Name + (++i).ToString();
            }

            if (uniqueName != contentType.Name)
            {
                contentType.Name = uniqueName;
            }

            var Url   = DNA.Utility.UrlUtility.CreateUrlHelper();
            var names = new List <string>();

            //        if (v.StartupScripts != null && !string.IsNullOrEmpty(v.StartupScripts.Source))
            //            view.StartupScripts = string.Format("<script type=\"text/javascript\" src=\"{0}\"></script>", Url.Content(pkg.ResolveUri(v.StartupScripts.Source, v.StartupScripts.Language.Equals(contentType.DefaultLocale, StringComparison.OrdinalIgnoreCase) ? "" : lang)));

            //        if (v.StyleSheet != null && !string.IsNullOrEmpty(v.StyleSheet.Source))
            //            view.StyleSheet = string.Format("<link type=\"text/css\" rel=\"StyleSheet\" href=\"{0}\"></script>", Url.Content(pkg.ResolveUri(v.StyleSheet.Source, v.StyleSheet.Language.Equals(contentType.DefaultLocale, StringComparison.OrdinalIgnoreCase) ? "" : lang)));

            #region unqurie slug
            if (contentType.Views != null)
            {
                foreach (var v in contentType.Views)
                {
                    var slug = v.Name;
                    var flex = slug;
                    var j    = 0;
                    while (names.Contains(slug))
                    {
                        slug = flex + (++j).ToString();
                    }
                    names.Add(slug);

                    if (v.Name != slug)
                    {
                        v.Name = slug;
                    }
                }

                if (contentType.Views.Count(v => v.IsDefault) == 0)
                {
                    contentType.Views.FirstOrDefault().IsDefault = true;
                }
            }
            #endregion

            var owner = this.HttpContext.User.Identity.Name;
            if (contentType.Items != null)
            {
                contentType.Items.AsParallel().ForAll(it =>
                {
                    if (string.IsNullOrEmpty(it.Owner))
                    {
                        it.Owner = owner;
                    }
                });
            }

            DataContext.Add(contentType);
            DataContext.SaveChanges();

            var webWrapper        = App.Get().Wrap(web);
            var defaultViewPageID = 0;

            if (contentType.Views != null)
            {
                foreach (var v in contentType.Views)
                {
                    #region new page

                    if (!v.NoPage)
                    {
                        var newpage = webWrapper.CreatePage(new ContentViewDecorator(v, DataContext), defaultViewPageID);
                        if (v.IsDefault)
                        {
                            defaultViewPageID = newpage.ID;
                            if (showInMenu)
                            {
                                newpage.Model.ShowInMenu = true;
                                //newpage.Save();
                            }
                        }
                    }

                    #endregion

                    DataContext.SaveChanges();
                }
            }

            //foreach (var f in contentType.Forms)
            //{
            //}

            var result = new ContentListDecorator(DataContext, contentType);
            App.Trigger("ContentListCreated", this, new ContentListEventArgs()
            {
                List = result
            });
            //new ContentListCreatedEvent(result).Raise(HttpContext);
            return(result);
        }
        /// <summary>
        /// Render an items tree for specified list 
        /// </summary>
        /// <param name="list">The content list object</param>
        /// <param name="current">The content data item object.</param>
        /// <param name="htmlAttributes">The html attributes object.</param>
        /// <returns></returns>
        public static HelperResult Tree(ContentListDecorator list, ContentDataItemDecorator current = null, object htmlAttributes = null)
        {
            return new HelperResult((w) =>
            {
                using (var writer = new Html32TextWriter(w))
                {
                    writer.WriteBeginTag("ul");
                    writer.WriteAttribute("data-role", "tree");
                    if (htmlAttributes != null)
                    {
                        var dict = htmlAttributes.ToDictionary();
                        foreach (var key in dict.Keys)
                        {
                            if (key.StartsWith("data_"))
                                writer.WriteAttribute(key.Replace("_", "-"), (string)dict[key]);
                            else
                                writer.WriteAttribute(key, (string)dict[key]);
                        }
                    }

                    writer.Write(Html32TextWriter.TagRightChar);
                    var items = list.GetItems(i => i.ParentItemID == Guid.Empty && i.IsPublished && i.IsCurrentVersion).OrderBy(i => i.Pos);
                    RenderChildren(writer, list, items, current);
                    writer.WriteEndTag("ul");
                }
            });
        }
Beispiel #16
0
 /// <summary>
 /// Initializes a new instance of the ContentItemTag class with content list.
 /// </summary>
 /// <param name="parent">The parent content list.</param>
 public ContentItemTag(ContentListDecorator parent)
 {
     this.Parent = parent;
 }
Beispiel #17
0
 /// <summary>
 /// Initializes a new instance of the ContentItemArchive class with content list object.
 /// </summary>
 /// <param name="parent"></param>
 public ContentItemArchive(ContentListDecorator parent)
 {
     this.Parent = parent;
 }
Beispiel #18
0
 /// <summary>
 /// Initializes a new instance of the ContentItemTag class with content list.
 /// </summary>
 /// <param name="parent">The parent content list.</param>
 public ContentItemTag(ContentListDecorator parent)
 {
     this.Parent = parent;
 }
Beispiel #19
0
 /// <summary>
 /// Initializes a new instance of the ContentItemArchive class with content list object.
 /// </summary>
 /// <param name="parent"></param>
 public ContentItemArchive(ContentListDecorator parent)
 {
     this.Parent = parent;
 }
        private static void RenderChildren(Html32TextWriter writer, ContentListDecorator list, IEnumerable <ContentDataItem> items, ContentDataItem current)
        {
            var app       = App.Get();
            var fieldName = list.GetDefaultTitleField().Name;
            var Url       = DNA.Utility.UrlUtility.CreateUrlHelper();

            foreach (var item in items)
            {
                var itemWrapper = app.Wrap(item);
                writer.WriteBeginTag("li");
                var _class        = "d-node";
                var children      = itemWrapper.Children();
                var childrenCount = children.Count();
                if (childrenCount > 0)
                {
                    _class += " d-node-hasChildren";
                }

                //writer.WriteAttribute("class", "d-node d-node-hasChildren");


                var isInPath = false;
                if (current != null && !string.IsNullOrEmpty(current.Path) && !string.IsNullOrEmpty(item.Path) && current.Path.StartsWith(item.Path))
                {
                    isInPath = true;
                    if (childrenCount > 0)
                    {
                        writer.WriteAttribute("data-expanded", "true");
                    }
                }
                writer.WriteAttribute("data-id", itemWrapper.ID.ToString());

                if (current != null && itemWrapper.ID.Equals(current.ID))
                {
                    writer.WriteAttribute("data-selected", "true");
                }

                if (itemWrapper.ParentItemID != Guid.Empty)
                {
                    writer.WriteAttribute("data-parentid", itemWrapper.ParentItemID.ToString());
                }

                if (childrenCount > 0)
                {
                    if (!isInPath)
                    {
                        var urlformat = "~/api/contents/items?name={0}&slug={1}&parentId={2}";
                        var popupUrl  = Url.Content(string.Format(urlformat, list.Name, list.Views.Default.Name, itemWrapper.ID.ToString()));
                        writer.WriteAttribute("data-popupurl", popupUrl);
                    }
                }
                writer.WriteAttribute("class", _class);
                writer.Write(Html32TextWriter.TagRightChar);

                writer.WriteBeginTag("a");
                writer.WriteAttribute("href", itemWrapper.UrlComponent);
                writer.Write(Html32TextWriter.TagRightChar);
                writer.Write(itemWrapper.Value(fieldName).Raw);
                writer.WriteEndTag("a");

                if (childrenCount > 0)
                {
                    if (isInPath)
                    {
                        writer.WriteFullBeginTag("ul");
                        RenderChildren(writer, list, children, current);
                        writer.WriteEndTag("ul");
                    }
                }

                writer.WriteEndTag("li");
            }
        }
Beispiel #21
0
        /// <summary>
        /// Create a new content list by specified content type.
        /// </summary>
        /// <param name="contentType">The content type object.</param>
        /// <param name="title">The content list title</param>
        /// <param name="name">The new content list name.</param>
        /// <returns>A content list object</returns>
        public ContentListDecorator CreateList(ContentList contentType, string title, string name)
        {
            var listNames = Lists.Select(l => l.Name).ToArray();

            if (contentType.IsSingle)
            {
                if (Context.Count <ContentList>(c => c.Name.Equals(contentType.BaseType)) > 0)
                {
                    throw new Exception("ContentType already created.");
                }
            }

            if (!string.IsNullOrEmpty(title))
            {
                contentType.Title = title;
                if (string.IsNullOrEmpty(name))
                {
                    contentType.Name = TextUtility.Slug(title);
                }
            }

            if (!string.IsNullOrEmpty(name))
            {
                contentType.Name = TextUtility.Slug(name);
            }

            contentType.WebID        = this.Id;
            contentType.Locale       = this.Culture;
            contentType.Owner        = this.Owner;
            contentType.LastModified = DateTime.Now;
            var uniqueName = contentType.Name;
            var i          = 0;

            while (listNames.Contains(uniqueName))
            {
                uniqueName = contentType.Name + (++i).ToString();
            }

            if (uniqueName != contentType.Name)
            {
                contentType.Name = uniqueName;
            }

            var Url   = DNA.Utility.UrlUtility.CreateUrlHelper();
            var names = new List <string>();

            //        if (v.StartupScripts != null && !string.IsNullOrEmpty(v.StartupScripts.Source))
            //            view.StartupScripts = string.Format("<script type=\"text/javascript\" src=\"{0}\"></script>", Url.Content(pkg.ResolveUri(v.StartupScripts.Source, v.StartupScripts.Language.Equals(contentType.DefaultLocale, StringComparison.OrdinalIgnoreCase) ? "" : lang)));

            //        if (v.StyleSheet != null && !string.IsNullOrEmpty(v.StyleSheet.Source))
            //            view.StyleSheet = string.Format("<link type=\"text/css\" rel=\"StyleSheet\" href=\"{0}\"></script>", Url.Content(pkg.ResolveUri(v.StyleSheet.Source, v.StyleSheet.Language.Equals(contentType.DefaultLocale, StringComparison.OrdinalIgnoreCase) ? "" : lang)));

            #region unqurie slug
            if (contentType.Views != null)
            {
                foreach (var v in contentType.Views)
                {
                    var slug = v.Name;
                    var flex = slug;
                    var j    = 0;
                    while (names.Contains(slug))
                    {
                        slug = flex + (++j).ToString();
                    }
                    names.Add(slug);

                    if (v.Name != slug)
                    {
                        v.Name = slug;
                    }
                }

                if (contentType.Views.Count(v => v.IsDefault) == 0)
                {
                    contentType.Views.FirstOrDefault().IsDefault = true;
                }
            }
            #endregion

            if (contentType.Items != null)
            {
                foreach (var dataItem in contentType.Items)
                {
                    if (dataItem.ID == Guid.Empty || Context.Find <ContentDataItem>(dataItem.ID) != null)
                    {
                        dataItem.ID = Guid.NewGuid();
                    }

                    dataItem.Locale = this.Culture;
                    if (string.IsNullOrEmpty(dataItem.Owner))
                    {
                        dataItem.Owner = this.Owner;
                    }
                }
            }

            Context.Add(contentType);
            Context.SaveChanges();
            var defaultViewPageID = 0;

            if (contentType.Views != null)
            {
                foreach (var v in contentType.Views)
                {
                    #region new page

                    if (!v.NoPage)
                    {
                        var newpage = CreatePage(new ContentViewDecorator(v, Context), defaultViewPageID);
                        if (newpage == null)
                        {
                            continue;
                        }

                        if (v.IsDefault)
                        {
                            defaultViewPageID = newpage.ID;
                        }
                    }

                    #endregion

                    Context.SaveChanges();
                }
            }
            var returns = new ContentListDecorator(Context, contentType);
            returns.ClearCache();
            return(returns);
        }
Beispiel #22
0
 internal PersonalListHelper(ContentListDecorator parent)
 {
     this._parent = parent;
 }