private void AddTagsFromProxy(ComposerTemplate engineComposerTemplate, ProxyComposer.ComposerTemplate proxyComposerTemplate)
        {
            if (proxyComposerTemplate.Tags == null || !proxyComposerTemplate.Tags.Any())
            {
                return;
            }

            engineComposerTemplate.Tags = proxyComposerTemplate.Tags
                                          .Select(pt => new Tag(pt.Name)
            {
                Excluded = false
            })
                                          .ToList();
        }
        private async Task AddComposerTemplateEntityViewFromProxy(CommerceContext commerceContext, ComposerTemplate engineComposerTemplate, ProxyComposer.ComposerTemplate proxyComposerTemplate)
        {
            var proxyEntityViewComponent = proxyComposerTemplate.Components.OfType <ProxyViews.EntityViewComponent>().FirstOrDefault();

            if (proxyEntityViewComponent == null ||
                proxyEntityViewComponent.View == null ||
                proxyEntityViewComponent.View.ChildViews == null ||
                !proxyEntityViewComponent.View.ChildViews.Any())
            {
                return;
            }

            var        proxyChildView        = proxyEntityViewComponent.View?.ChildViews[0] as ProxyEntityViews.EntityView;
            EntityView engineEntityChildView = new EntityView();

            engineEntityChildView.ItemId      = proxyChildView.ItemId;
            engineEntityChildView.EntityId    = proxyChildView.EntityId;
            engineEntityChildView.Name        = proxyChildView?.Name;
            engineEntityChildView.DisplayName = proxyChildView.DisplayName;
            engineEntityChildView.Icon        = proxyChildView.Icon;
            engineEntityChildView.DisplayRank = proxyChildView.DisplayRank;

            var isNameValid = await this.RunValidCheckOnName(engineEntityChildView, commerceContext);

            if (!isNameValid)
            {
                return;
            }

            engineComposerTemplate.GetComponent <EntityViewComponent>().AddChildView(engineEntityChildView);
            if (proxyChildView.Properties != null)
            {
                foreach (var proxyViewProperty in proxyChildView.Properties)
                {
                    await this.AddPropertyToViewFromProxy(commerceContext, engineEntityChildView, proxyViewProperty);
                }
            }
        }
        private void AddComposerTemplateListMembershipsFromProxy(ComposerTemplate engineComposerTemplate, ProxyComposer.ComposerTemplate proxyComposerTemplate)
        {
            var proxyListMembershipComponent = proxyComposerTemplate?.Components?.OfType <ProxyManagedLists.ListMembershipsComponent>().FirstOrDefault();

            if (proxyListMembershipComponent == null)
            {
                return;
            }

            foreach (var membership in proxyListMembershipComponent.Memberships)
            {
                engineComposerTemplate.GetComponent <ListMembershipsComponent>().Memberships.Add(membership);
            }
        }
        public virtual async Task CreateTemplateFromProxy(CommerceContext commerceContext, ProxyComposer.ComposerTemplate proxyComposerTemplate)
        {
            ComposerCommander composerCommander = this;

            Condition.Requires(commerceContext).IsNotNull("CommerceContext");
            Condition.Requires(proxyComposerTemplate).IsNotNull("composerTemplate");
            using (CommandActivity.Start(commerceContext, composerCommander))
            {
                KnownResultCodes errorCodes           = commerceContext.GetPolicy <KnownResultCodes>();
                string           composerTemplateName = proxyComposerTemplate.Name;
                if (string.IsNullOrEmpty(composerTemplateName))
                {
                    string composerTemplatePropertyName = "Name";
                    string str2 = await commerceContext.AddMessage(errorCodes.ValidationError, "InvalidOrMissingPropertyValue", new object[1]
                    {
                        composerTemplatePropertyName
                    }, "Invalid or missing value for property '" + composerTemplatePropertyName + "'.").ConfigureAwait(false);

                    return;
                }
                string templateId = proxyComposerTemplate.Id;
                if (await composerCommander.GetEntity <ComposerTemplate>(commerceContext, templateId, false).ConfigureAwait(false) != null)
                {
                    string str = await commerceContext.AddMessage(errorCodes.ValidationError, "NameAlreadyInUse", new object[1]
                    {
                        proxyComposerTemplate.Name
                    }, "Name '" + proxyComposerTemplate.Name + "' is already in use.").ConfigureAwait(false);

                    return;
                }

                ComposerTemplate engineComposerTemplate = new ComposerTemplate(templateId);
                engineComposerTemplate.Name           = proxyComposerTemplate.Name;
                engineComposerTemplate.DisplayName    = proxyComposerTemplate.DisplayName;
                engineComposerTemplate.FriendlyId     = proxyComposerTemplate.Name;
                engineComposerTemplate.LinkedEntities = proxyComposerTemplate.LinkedEntities;

                this.AddTagsFromProxy(engineComposerTemplate, proxyComposerTemplate);
                this.AddComposerTemplateListMembershipsFromProxy(engineComposerTemplate, proxyComposerTemplate);
                await this.AddComposerTemplateEntityViewFromProxy(commerceContext, engineComposerTemplate, proxyComposerTemplate);

                this.AddItemDefinitionsFromProxy(engineComposerTemplate, proxyComposerTemplate);

                int num = await composerCommander.PersistEntity(commerceContext, engineComposerTemplate).ConfigureAwait(false) ? 1 : 0;

                errorCodes = null;
                templateId = null;
            }
        }
        private void AddItemDefinitionsFromProxy(ComposerTemplate engineComposerTemplate, ProxyComposer.ComposerTemplate proxyComposerTemplate)
        {
            var proxyItemDefinitionsComponent = proxyComposerTemplate?.Components?.OfType <ProxyCatalog.ItemDefinitionsComponent>().FirstOrDefault();

            if (proxyItemDefinitionsComponent == null)
            {
                return;
            }

            engineComposerTemplate.GetComponent <ItemDefinitionsComponent>().AddDefinitions(proxyItemDefinitionsComponent.Definitions);
        }