private List <Product> GetProductsByCategoryFromBDC(string categoryId)
        {
            List <Product> products = new List <Product>();

            IEntityInstance          sourceCategory = CategoryEntity.FindSpecific(categoryId, ProductCatalogSystem);
            EntityInstanceCollection source         = new EntityInstanceCollection();

            if (source != null)
            {
                source.Add(sourceCategory);
            }

            IEntityInstanceEnumerator entitiesEnumerator = ProductEntity.FindAssociated(source, ProductCatalogSystem);

            while (entitiesEnumerator.MoveNext())
            {
                IEntityInstance productInstance = entitiesEnumerator.Current;

                Product product = new Product();
                product.CategoryId       = (string)productInstance["CategoryId"];
                product.ImagePath        = (string)productInstance["ImagePath"];
                product.LongDescription  = (string)productInstance["LongDescription"];
                product.ShortDescription = (string)productInstance["ShortDescription"];
                product.Name             = (string)productInstance["Name"];
                product.Sku = (string)productInstance["Sku"];
                product.ThumbnailImagePath = (string)productInstance["ThumbnailImagePath"];

                products.Add(product);
                SetCachedProduct(product);
            }

            return(products);
        }
        private List <Category> GetChildCategoriesByCategoryFromBDC(string categoryId)
        {
            List <Category> categories = new List <Category>();

            if (!string.IsNullOrEmpty(categoryId))
            {
                IEntityInstance          sourceCategory = CategoryEntity.FindSpecific(categoryId, ProductCatalogSystem);
                EntityInstanceCollection source         = new EntityInstanceCollection();
                if (sourceCategory != null)
                {
                    source.Add(sourceCategory);
                }

                IEntityInstanceEnumerator instanceEnumerator = CategoryEntity.FindAssociated(source,
                                                                                             ProductCatalogSystem);
                while (instanceEnumerator.MoveNext())
                {
                    IEntityInstance categoryInstance = instanceEnumerator.Current;
                    Category        category         = new Category();
                    category.CategoryId = (string)categoryInstance["CategoryId"];
                    category.Name       = (string)categoryInstance["Name"];
                    category.ParentId   = (string)categoryInstance["ParentId"];

                    categories.Add(category);

                    string key = typeof(Category).FullName + categoryId;
                    cache.Add(key, categories, null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(5f),
                              CacheItemPriority.Normal, null);
                }
            }

            return(categories);
        }
        /// <summary>
        /// Gets the parts for a particular product specified by it's sku.
        /// </summary>
        /// <param name="sku">The sku to retrieve parts for.</param>
        /// <returns>The parts for this product.</returns>
        public IEnumerable <Part> GetPartsByProductSku(string sku)
        {
            List <Part> parts = new List <Part>();

            IEntityInstance          sourceProduct = ProductEntity.FindSpecific(sku, ProductCatalogSystem);
            EntityInstanceCollection source        = new EntityInstanceCollection();

            if (source != null)
            {
                source.Add(sourceProduct);
            }

            IEntityInstanceEnumerator entitiesEnumerator = PartEntity.FindAssociated(source, ProductCatalogSystem);

            while (entitiesEnumerator.MoveNext())
            {
                IEntityInstance partInstance = entitiesEnumerator.Current;

                Part part = new Part();
                part.Name   = (string)partInstance["Name"];
                part.PartId = (string)partInstance["PartId"];
                parts.Add(part);
            }

            return(parts);
        }
Ejemplo n.º 4
0
        //this method uses an Association from the model to return Items associated with the selected machine
        public List <BdcPart> GetPartsByMachineId(int machineId)
        {
            //Get Destination entity and Association
            IEntity      entity      = catalog.GetEntity(Constants.BdcEntityNameSpace, "Parts");
            IAssociation association = (IAssociation)entity.GetMethodInstance("GetPartsByMachineID", MethodInstanceType.AssociationNavigator);

            //Get Source entity and add to collection (required for method call)
            IEntityInstance          machineInstance = GetBdcEntityInstance(machineId, "Machines");
            EntityInstanceCollection collection      = new EntityInstanceCollection();

            collection.Add(machineInstance);

            // Navigate the association.
            IEntityInstanceEnumerator associatedInstances = entity.FindAssociated(collection, association, partsManagementLobSystemInstance, OperationMode.Online);

            //Return a collection of View Models from the associated Data Table
            return(new DataMapper <BdcPart>(entity.Catalog.Helper.CreateDataTable(associatedInstances)).Collection);
        }