public IEnumerable <CategoryAttributes> Category([FromRoute] int id)
        {
            try
            {
                _attributes = _attributeListRepository.GetAll().ToList();
                foreach (var attributeDetail in _attributes)
                {
                    if (attributeDetail.CategoryId == id)
                    {
                        _attribute.Id          = attributeDetail.Id;
                        _attribute.IsMandatory = attributeDetail.IsMandatory;
                        _attribute.Name        = attributeDetail.Name;
                        _attribute.Type        = attributeDetail.Type;
                        _categoryAttributes.Add(_attribute);
                        _attribute = new CategoryAttributes();
                    }
                }

                return(_categoryAttributes);
            }
            catch (Exception)
            {
                return(_categoryAttributes);
            }
        }
 public CategorySelectController(ICategoryRepository categoryRepository,
                                 IAttributeDetailRepository attributeListRepository)
 {
     _categoryRepository      = categoryRepository;
     _attributeListRepository = attributeListRepository;
     _attribute    = new CategoryAttributes();
     _categoryItem = new Category();
     _attributes   = new List <AttributeDetail>();
     _category     = new List <Category>();
 }
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="arg">
        /// The pipeline argument.
        /// </param>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The <see cref="PipelineArgument"/>.
        /// </returns>
        public override Task <EntityView> Run(EntityView arg, CommercePipelineExecutionContext context)
        {
            Condition.Requires(arg).IsNotNull($"{Name}: The argument cannot be null.");


            var sellableItemStiboAttributesViewsPolicy = context.GetPolicy <CategoryAttributesActionPolicy>();

            // Only proceed if the right action was invoked
            if (string.IsNullOrEmpty(arg.Action) || !arg.Action.Equals(sellableItemStiboAttributesViewsPolicy.CategoryAttributes, StringComparison.OrdinalIgnoreCase))
            {
                return(Task.FromResult(arg));
            }

            // Get the sellable item from the context

            var sellableItemEntity       = context.CommerceContext.GetObject <Sitecore.Commerce.Plugin.Catalog.SellableItem>(x => x.Id.Equals(arg.EntityId));
            var categoryEntity           = context.CommerceContext.GetObject <Sitecore.Commerce.Plugin.Catalog.Category>(x => x.Id.Equals(arg.EntityId));
            CategoryAttributes component = null;

            // Get the component from the sellable item or its variation
            if (sellableItemEntity != null)
            {
                if (!string.IsNullOrWhiteSpace(arg.ItemId))
                {
                    component = sellableItemEntity.GetVariation(arg.ItemId).GetComponent <CategoryAttributes>();
                }
                else
                {
                    component = sellableItemEntity.GetComponent <CategoryAttributes>();
                }
            }
            if (categoryEntity != null)
            {
                component = categoryEntity.GetComponent <CategoryAttributes>();
            }

            if (component != null)
            {
                component.SitecoreMappingPath =
                    arg.Properties.FirstOrDefault(x =>
                                                  x.Name.Equals(nameof(CategoryAttributes.SitecoreMappingPath), StringComparison.OrdinalIgnoreCase))?.Value;

                component.ClassificationType =
                    arg.Properties.FirstOrDefault(x =>
                                                  x.Name.Equals(nameof(CategoryAttributes.ClassificationType), StringComparison.OrdinalIgnoreCase))?.Value;
            }

            if (sellableItemEntity != null)
            {
                context.Logger.LogInformation("Current Entity Version : " + sellableItemEntity.Version);

                // Persist changes
                this.Commander.Pipeline <IPersistEntityPipeline>().Run(new PersistEntityArgument(sellableItemEntity), context);
            }
            if (categoryEntity != null)
            {
                context.Logger.LogInformation("Current Entity Version : " + categoryEntity.Version);

                // Persist changes
                this.Commander.Pipeline <IPersistEntityPipeline>().Run(new PersistEntityArgument(categoryEntity), context);
            }

            return(Task.FromResult(arg));
        }
        public override Task <EntityView> Run(EntityView arg, CommercePipelineExecutionContext context)
        {
            Condition.Requires(arg).IsNotNull($"{Name}: The argument cannot be null.");

            var request = this._viewCommander.CurrentEntityViewArgument(context.CommerceContext);

            var catalogViewsPolicy = context.GetPolicy <KnownCatalogViewsPolicy>();

            var sellableitemstiboattributesviewspolicy = context.GetPolicy <SellableItemStiboAttributesViewsPolicy>();

            var isVariationView = request.ViewName.Equals(catalogViewsPolicy.Variant, StringComparison.OrdinalIgnoreCase);
            var isConnectView   = arg.Name.Equals(catalogViewsPolicy.ConnectSellableItem, StringComparison.OrdinalIgnoreCase);

            // Only proceed if the current entity is a sellable item or Category
            if ((request.Entity is Sitecore.Commerce.Plugin.Catalog.Category) || (request.Entity is Sitecore.Commerce.Plugin.Catalog.SellableItem))
            {
                // Make sure that we target the correct views
                if (string.IsNullOrEmpty(request.ViewName) ||
                    !request.ViewName.Equals(catalogViewsPolicy.Master, StringComparison.OrdinalIgnoreCase) &&
                    !request.ViewName.Equals(catalogViewsPolicy.Details, StringComparison.OrdinalIgnoreCase) &&
                    !request.ViewName.Equals(sellableitemstiboattributesviewspolicy.CategoryAttributes, StringComparison.OrdinalIgnoreCase) &&
                    !isVariationView &&
                    !isConnectView)
                {
                    return(Task.FromResult(arg));
                }
                Sitecore.Commerce.Plugin.Catalog.SellableItem sellableItem = null; Sitecore.Commerce.Plugin.Catalog.Category category = null; var variationId = string.Empty;
                if (request.Entity is Sitecore.Commerce.Plugin.Catalog.SellableItem)
                {
                    sellableItem = (Sitecore.Commerce.Plugin.Catalog.SellableItem)request.Entity;
                }
                if (request.Entity is Sitecore.Commerce.Plugin.Catalog.Category)
                {
                    category = (Sitecore.Commerce.Plugin.Catalog.Category)request.Entity;
                }


                CategoryAttributes component = null;
                if (category != null)
                {
                    component = category.GetComponent <CategoryAttributes>();
                }

                // See if we are dealing with the base sellable item or one of its variations.
                if (sellableItem != null)
                {
                    if (isVariationView && !string.IsNullOrEmpty(arg.ItemId))
                    {
                        variationId = arg.ItemId;
                        component   = sellableItem.GetVariation(variationId).GetComponent <CategoryAttributes>();
                    }
                    else if (!string.IsNullOrEmpty(arg.ItemId) && arg.VersionedItemId != ("-1"))
                    {
                        variationId = arg.ItemId;
                        component   = sellableItem.GetVariation(variationId).GetComponent <CategoryAttributes>();
                    }
                    else
                    {
                        component = sellableItem.GetComponent <CategoryAttributes>(variationId);
                    }
                }

                var  targetView = arg;
                bool isEditView = false;

                #region 16. Category Mapping
                isEditView = !string.IsNullOrEmpty(arg.Action) && arg.Action.Equals(sellableitemstiboattributesviewspolicy.CategoryAttributes, StringComparison.OrdinalIgnoreCase);
                if (!isEditView)
                {
                    // Create a new view and add it to the current entity view.
                    var view = new EntityView
                    {
                        Name          = context.GetPolicy <SellableItemStiboAttributesViewsPolicy>().CategoryAttributes,
                        DisplayName   = "Category Mapping",
                        EntityId      = arg.EntityId,
                        DisplayRank   = 2,
                        EntityVersion = arg.EntityVersion,
                        ItemId        = variationId,
                        Icon          = "piece",
                    };

                    arg.ChildViews.Add(view);
                    targetView = view;
                }

                AddSellableItemProperties.AddPropertiesToViewWithSection(targetView, component, Models.ProductContsants.NonEditableField, nameof(component.SitecoreMappingPath), component.SitecoreMappingPath, component.GetDisplayName(nameof(component.SitecoreMappingPath)));

                AddSellableItemProperties.AddPropertiesToViewWithSection(targetView, component, Models.ProductContsants.NonEditableField, nameof(component.ClassificationType), component.ClassificationType, component.GetDisplayName(nameof(component.ClassificationType)));
                #endregion
            }
            return(Task.FromResult(arg));
        }