public IEnumerable <ISOProduct> ExportProducts(IEnumerable <Product> adaptProducts)
        {
            List <ISOProduct> isoProducts = new List <ISOProduct>();

            //Add all the products
            foreach (Product adaptProduct in adaptProducts)
            {
                ISOProduct product = ExportProduct(adaptProduct);
                isoProducts.Add(product);
            }

            //Fill in detail on the product mixes
            if (adaptProducts.OfType <MixProduct>().Any())
            {
                foreach (MixProduct adaptMixProduct in adaptProducts.OfType <MixProduct>())
                {
                    //Find the ISO Product
                    ISOProduct isoMixProduct = isoProducts.Single(p => p.ProductId == TaskDataMapper.InstanceIDMap.GetISOID(adaptMixProduct.Id.ReferenceId));

                    foreach (ProductComponent component in adaptMixProduct.ProductComponents)
                    {
                        Ingredient ingredient = DataModel.Catalog.Ingredients.FirstOrDefault(i => i.Id.ReferenceId == component.IngredientId);
                        if (ingredient != null)
                        {
                            ISOProduct componentProduct = isoProducts.FirstOrDefault(p => p.ProductDesignator == ingredient.Description); //Matches on name; assumes all ingredients are also products
                            if (componentProduct != null)
                            {
                                //Create PRNs if we can match to pre-existing products
                                ISOProductRelation relation = new ISOProductRelation();
                                relation.ProductIdRef  = componentProduct.ProductId;
                                relation.QuantityValue = component.Quantity.AsIntViaMappedDDI(RepresentationMapper);
                                isoMixProduct.ProductRelations.Add(relation);
                            }
                        }
                    }

                    //Total Quantity
                    isoMixProduct.MixtureRecipeQuantity = adaptMixProduct.TotalQuantity.AsIntViaMappedDDI(RepresentationMapper);

                    //Quantity DDI
                    int?ddi = RepresentationMapper.Map(adaptMixProduct.TotalQuantity.Representation);
                    if (ddi.HasValue)
                    {
                        isoMixProduct.QuantityDDI = ddi.Value.AsHexDDI();
                    }
                }
            }
            return(isoProducts);
        }
Exemple #2
0
        private void ExportProductRelation(List <ISOProduct> isoProducts,
                                           string adaptDescription,
                                           ApplicationDataModel.Representations.NumericRepresentationValue quantity,
                                           ISOProduct targetMixProduct)
        {
            ISOProduct componentProduct = isoProducts.FirstOrDefault(p => p.ProductDesignator == adaptDescription); //Matches on name; assumes all ingredients are also products

            if (componentProduct != null)
            {
                //Create PRNs if we can match to pre-existing products
                ISOProductRelation relation = new ISOProductRelation();
                relation.ProductIdRef  = componentProduct.ProductId;
                relation.QuantityValue = quantity.AsIntViaMappedDDI(RepresentationMapper);
                targetMixProduct.ProductRelations.Add(relation);
            }
        }