/// <summary>
        /// Converts an instance of Component into an instance of GetComponentModelView.
        /// </summary>
        /// <param name="component">Instance of Component.</param>
        /// <returns>An instance of GetComponentModelView.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when the provided instance of Component is null.
        /// </exception>
        public static GetComponentModelView fromEntity(Component component, string unit)
        {
            if (component == null)
            {
                throw new ArgumentNullException(ERROR_NULL_COMPONENT);
            }

            GetComponentModelView componentModelView = new GetComponentModelView();

            componentModelView.productId     = component.complementaryProductId;
            componentModelView.reference     = component.complementaryProduct.reference;
            componentModelView.designation   = component.complementaryProduct.designation;
            componentModelView.modelFilename = component.complementaryProduct.modelFilename;
            componentModelView.mandatory     = component.mandatory;
            componentModelView.category      = ProductCategoryModelViewService.fromEntityAsBasic(component.complementaryProduct.productCategory);
            if (component.complementaryProduct.components.Any())
            {
                componentModelView.components = ComponentModelViewService.fromCollection(component.complementaryProduct.components);
            }
            //no need to check if the product has materials and measurements, since they're mandatory
            componentModelView.materials    = ProductMaterialModelViewService.fromCollection(component.complementaryProduct.productMaterials);
            componentModelView.measurements = MeasurementModelViewService.fromCollection(component.complementaryProduct.productMeasurements.Select(pm => pm.measurement), unit);
            if (component.complementaryProduct.supportsSlots)
            {
                componentModelView.slotWidths = ProductSlotWidthsModelViewService.fromEntity(component.complementaryProduct.slotWidths, unit);
            }

            /*Skip converting Restrictions if the Component has none,
             * since null GetAllRestrictionsModelView won't be serialized */
            if (component.restrictions.Any())
            {
                componentModelView.restrictions = RestrictionModelViewService.fromCollection(component.restrictions);
            }
            return(componentModelView);
        }
Exemple #2
0
        /// <summary>
        /// Creates a model view with a product information.
        /// </summary>
        /// <param name="product">Product with the product being created the model view.</param>
        /// <param name="unit">Unit to which all the dimension data will be converted to.</param>
        /// <returns>GetProductModelView with the product information model view</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the provided instance of Product is null.</exception>
        public static GetProductModelView fromEntity(Product product, string unit)
        {
            if (product == null)
            {
                throw new ArgumentNullException(ERROR_NULL_PRODUCT);
            }

            GetProductModelView productModelView = new GetProductModelView();

            productModelView.productId     = product.Id;
            productModelView.reference     = product.reference;
            productModelView.designation   = product.designation;
            productModelView.modelFilename = product.modelFilename;
            productModelView.category      = ProductCategoryModelViewService.fromEntityAsBasic(product.productCategory);
            if (product.components.Any())
            {
                productModelView.components = ComponentModelViewService.fromCollection(product.components);
            }
            //no need to check if the product has materials and measurements, since they're mandatory
            productModelView.materials    = ProductMaterialModelViewService.fromCollection(product.productMaterials);
            productModelView.measurements = MeasurementModelViewService.fromCollection(product.productMeasurements.Select(pm => pm.measurement), unit);
            if (product.supportsSlots)
            {
                productModelView.slotWidths = ProductSlotWidthsModelViewService.fromEntity(product.slotWidths, unit);
            }
            return(productModelView);
        }