Esempio n. 1
0
 /// <summary>
 /// Create a new content list by specified content type element.
 /// </summary>
 /// <param name="listElement">The content list element</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(XElement listElement, string title = "", string name = "")
 {
     var list = new ContentList();
     list.Load(listElement);
     return CreateList(list, title, name);
 }
Esempio n. 2
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);
        }
Esempio n. 3
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;
        }