Example #1
0
        /// <summary>Find out if an item name is occupied.</summary>
        /// <param name="name">The name to check.</param>
        /// <param name="item">The item whose siblings (other items with the same parent) might be have a clashing name.</param>
        /// <returns>True if the name is unique.</returns>
        public bool IsLocallyUnique(string name, ContentItem item)
        {
            //this causes an error if in install mode due to the root node not being installed yet so can't add Language Container which is needed to check if root node is unique!
            //so check mode - if in install it's safe to assume this code isn't needed
            if (_adminConfig.Installer.Mode != InstallationMode.Install)
            {
                ContentItem parentItem = item.GetParent();
                if (parentItem != null)
                    foreach (ContentItem potentiallyClashingItem in parentItem.Children)
                        if (!potentiallyClashingItem.Equals(item) && potentiallyClashingItem != item.TranslationOf)
                            foreach (ContentItem translation in _languageManager.GetTranslationsOf(potentiallyClashingItem, true))
                                if (!translation.Equals(item) && translation.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase))
                                    return false;
            }

            return true;
        }
Example #2
0
        /// <summary>Check if an item can be saved.</summary>
        /// <exception cref="NameOccupiedException"></exception>
        /// <exception cref="ZeusException"></exception>
        public virtual ZeusException GetSaveException(ContentItem item)
        {
            if (!IsLocallyUnique(item.Name, item))
                return new NameOccupiedException(item, item.GetParent());

            if (!IsTypeAllowedBelowDestination(item, item.Parent))
                return new NotAllowedParentException(_contentTypeManager.GetContentType(item.GetType()), item.GetParent().GetType());

            return null;
        }