Ejemplo n.º 1
0
        /// <summary>
        /// This method creates a container page under a parent, based on a given name
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="childName">Name of the child.</param>
        /// <param name="language"></param>
        /// <returns></returns>
        protected ContentReference CreateChildUnderContainer(ContentReference parent, int childName, string language)
        {
            //1. Create a new MediaContainer page with the name of the childName
            //2. Return the newly created PageReference

            try
            {
                if (YearContainerPageTypeId == 0)
                {
                    return(parent);
                }
                ContentReference otherLanguage = null;
                foreach (PageData child in ContentRepository.GetChildren <PageData>(parent, LanguageSelector.MasterLanguage()))
                {
                    if (string.Compare(child.PageName, childName.ToString(), true) == 0)
                    {
                        otherLanguage = child.PageLink;
                        break;
                    }
                }

                if (otherLanguage == null)
                {
                    // first add the first language of the year container, then loop through other language of the start page.
                    //ContentReference yearContainer;
                    CultureInfo mainLanguage = new CultureInfo("en");
                    PageData    yearPage     = ContentRepository.GetDefault <PageData>(
                        parent,
                        YearContainerPageTypeId,
                        mainLanguage);

                    yearPage.PageName = childName.ToString();
                    otherLanguage     = ContentRepository.Save(yearPage, SaveAction.Publish, AccessLevel.NoAccess);
                }
                if (language != "en")
                {
                    CultureInfo langSel  = new CultureInfo(language);
                    var         yearPage = ContentRepository.CreateLanguageBranch <PageData>(otherLanguage, langSel);
                    yearPage.PageName = childName.ToString();

                    ContentRepository.Save(yearPage, SaveAction.Publish, AccessLevel.NoAccess);
                }
                return(otherLanguage);
            }
            catch
            {
                return(ContentReference.EmptyReference);
            }
        }