private void CopyChildContents(IList <ChildContent> destinationChildren, IList <ChildContent> sourceChildren)
        {
            // Update all child and their options
            foreach (var sourceChildContent in sourceChildren)
            {
                var destinationChildContent = destinationChildren.FirstOrDefault(d => sourceChildContent.AssignmentIdentifier == d.AssignmentIdentifier);
                if (destinationChildContent == null)
                {
                    destinationChildContent = new ChildContent();
                    destinationChildren.Add(destinationChildContent);
                }

                destinationChildContent.AssignmentIdentifier = sourceChildContent.AssignmentIdentifier;
                destinationChildContent.Child = sourceChildContent.Child;

                // Update all the options
                if (sourceChildContent.Options == null)
                {
                    sourceChildContent.Options = new List <ChildContentOption>();
                }
                if (destinationChildContent.Options == null)
                {
                    destinationChildContent.Options = new List <ChildContentOption>();
                }

                // Add new options
                foreach (var sourceChildOption in sourceChildContent.Options)
                {
                    var destinationChildOption = destinationChildContent.Options.FirstOrDefault(o => o.Key == sourceChildOption.Key);
                    if (destinationChildOption == null)
                    {
                        destinationChildOption = new ChildContentOption();
                        destinationChildContent.Options.Add(destinationChildOption);
                    }
                    sourceChildOption.CopyDataTo(destinationChildOption, false);
                    if (sourceChildOption.Translations != null)
                    {
                        foreach (var childContentOptionTranslation in sourceChildOption.Translations)
                        {
                            var languageId  = childContentOptionTranslation.Language.Id;
                            var translation = destinationChildOption.Translations.FirstOrDefault(x => x.Language.Id == languageId);
                            if (translation == null)
                            {
                                translation = childContentOptionTranslation.Clone();
                            }
                            else
                            {
                                translation.Value = childContentOptionTranslation.Value;
                            }
                            translation.ChildContentOption = destinationChildOption;
                            destinationChildOption.Translations.Add(translation);
                        }
                    }

                    destinationChildOption.ChildContent = destinationChildContent;
                }
            }
        }
Beispiel #2
0
        public ChildContentOption CreateNewChildContentOption(ChildContent childContent = null)
        {
            var entity = new ChildContentOption();

            PopulateBaseFields(entity);

            entity.Key             = ProvideRandomString(MaxLength.Name);
            entity.ChildContent    = childContent ?? CreateNewChildContent();
            entity.Type            = ProvideRandomEnumValue <OptionType>();
            entity.UseDefaultValue = false;
            entity.Value           = ProvideRandomString(100);

            return(entity);
        }
        private IList <ChildContent> GetChildContents(Guid[] ids, bool canManageContent)
        {
            ChildContent       ccAlias       = null;
            ChildContentOption ccOptionAlias = null;

            Models.Content childAlias   = null;
            ContentOption  cOptionAlias = null;
            ContentRegion  cRegionAlias = null;
            Region         regionAlias  = null;

            ChildContent ccAlias1 = null;

            Models.Content ccChildAlias   = null;
            Models.Content historyAlias   = null;
            ChildContent   historyCcAlias = null;

            Models.Content historyChildAlias = null;

            var query = repository
                        .AsQueryOver(() => ccAlias)
                        .Where(Restrictions.In(NHibernate.Criterion.Projections.Property(() => ccAlias.Parent.Id), ids))
                        .And(() => !ccAlias.IsDeleted)
                        .Inner.JoinAlias(() => ccAlias.Child, () => childAlias)
                        .Where(() => !childAlias.IsDeleted)
                        .Left.JoinAlias(() => childAlias.ContentOptions, () => cOptionAlias)
                        .Left.JoinAlias(() => ccAlias.Options, () => ccOptionAlias)

                        .Left.JoinAlias(() => childAlias.ContentRegions, () => cRegionAlias)
                        .Left.JoinAlias(() => cRegionAlias.Region, () => regionAlias)

                        .Left.JoinAlias(() => childAlias.ChildContents, () => ccAlias1)
                        .Left.JoinAlias(() => ccAlias1.Child, () => ccChildAlias);

            if (canManageContent)
            {
                query = query
                        .Left.JoinAlias(() => childAlias.History, () => historyAlias)
                        .Left.JoinAlias(() => historyAlias.ChildContents, () => historyCcAlias)
                        .Left.JoinAlias(() => historyCcAlias.Child, () => historyChildAlias);
            }


            return(query.List <ChildContent>());
        }
        private void CopyChildContents(IList <ChildContent> destinationChildren, IList <ChildContent> sourceChildren)
        {
            // Update all child and their options
            foreach (var sourceChildContent in sourceChildren)
            {
                var destinationChildContent = destinationChildren.FirstOrDefault(d => sourceChildContent.AssignmentIdentifier == d.AssignmentIdentifier);
                if (destinationChildContent == null)
                {
                    destinationChildContent = new ChildContent();
                    destinationChildren.Add(destinationChildContent);
                }

                destinationChildContent.AssignmentIdentifier = sourceChildContent.AssignmentIdentifier;
                destinationChildContent.Child = sourceChildContent.Child;

                // Update all the options
                if (sourceChildContent.Options == null)
                {
                    sourceChildContent.Options = new List <ChildContentOption>();
                }
                if (destinationChildContent.Options == null)
                {
                    destinationChildContent.Options = new List <ChildContentOption>();
                }

                // Add new options
                foreach (var sourceChildOption in sourceChildContent.Options)
                {
                    var destinationChildOption = destinationChildContent.Options.FirstOrDefault(o => o.Key == sourceChildOption.Key);
                    if (destinationChildOption == null)
                    {
                        destinationChildOption = new ChildContentOption();
                        destinationChildContent.Options.Add(destinationChildOption);
                    }

                    sourceChildOption.CopyDataTo(destinationChildOption);
                    destinationChildOption.ChildContent = destinationChildContent;
                }
            }
        }
        private void CopyChildContents(IList<ChildContent> destinationChildren, IList<ChildContent> sourceChildren)
        {
            // Update all child and their options
            foreach (var sourceChildContent in sourceChildren)
            {
                var destinationChildContent = destinationChildren.FirstOrDefault(d => sourceChildContent.AssignmentIdentifier == d.AssignmentIdentifier);
                if (destinationChildContent == null)
                {
                    destinationChildContent = new ChildContent();
                    destinationChildren.Add(destinationChildContent);
                }

                destinationChildContent.AssignmentIdentifier = sourceChildContent.AssignmentIdentifier;
                destinationChildContent.Child = sourceChildContent.Child;

                // Update all the options
                if (sourceChildContent.Options == null)
                {
                    sourceChildContent.Options = new List<ChildContentOption>();
                }
                if (destinationChildContent.Options == null)
                {
                    destinationChildContent.Options = new List<ChildContentOption>();
                }

                // Add new options
                foreach (var sourceChildOption in sourceChildContent.Options)
                {
                    var destinationChildOption = destinationChildContent.Options.FirstOrDefault(o => o.Key == sourceChildOption.Key);
                    if (destinationChildOption == null)
                    {
                        destinationChildOption = new ChildContentOption();
                        destinationChildContent.Options.Add(destinationChildOption);
                    }
                    sourceChildOption.CopyDataTo(destinationChildOption, false);
                    if (sourceChildOption.Translations != null)
                    {
                        foreach (var childContentOptionTranslation in sourceChildOption.Translations)
                        {
                            var languageId = childContentOptionTranslation.Language.Id;
                            var translation = destinationChildOption.Translations.FirstOrDefault(x => x.Language.Id == languageId);
                            if (translation == null)
                            {
                                translation = childContentOptionTranslation.Clone();
                            }
                            else
                            {
                                translation.Value = childContentOptionTranslation.Value;
                            }
                            translation.ChildContentOption = destinationChildOption;
                            destinationChildOption.Translations.Add(translation);
                        }
                    }

                    destinationChildOption.ChildContent = destinationChildContent;
                }
            }
        }
        private void CopyChildContents(IList<ChildContent> destinationChildren, IList<ChildContent> sourceChildren)
        {
            // Update all child and their options
            foreach (var sourceChildContent in sourceChildren)
            {
                var destinationChildContent = destinationChildren.FirstOrDefault(d => sourceChildContent.AssignmentIdentifier == d.AssignmentIdentifier);
                if (destinationChildContent == null)
                {
                    destinationChildContent = new ChildContent();
                    destinationChildren.Add(destinationChildContent);
                }

                destinationChildContent.AssignmentIdentifier = sourceChildContent.AssignmentIdentifier;
                destinationChildContent.Child = sourceChildContent.Child;

                // Update all the options
                if (sourceChildContent.Options == null)
                {
                    sourceChildContent.Options = new List<ChildContentOption>();
                }
                if (destinationChildContent.Options == null)
                {
                    destinationChildContent.Options = new List<ChildContentOption>();
                }

                // Add new options
                foreach (var sourceChildOption in sourceChildContent.Options)
                {
                    var destinationChildOption = destinationChildContent.Options.FirstOrDefault(o => o.Key == sourceChildOption.Key);
                    if (destinationChildOption == null)
                    {
                        destinationChildOption = new ChildContentOption();
                        destinationChildContent.Options.Add(destinationChildOption);
                    }

                    sourceChildOption.CopyDataTo(destinationChildOption);
                    destinationChildOption.ChildContent = destinationChildContent;
                }
            }
        }