/// <summary> /// Converts an IEnumerable of Component into an instance of GetAllComponentsGroupedByCategoryModelView. /// </summary> /// <param name="components">IEnumerable of Component being converted.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException"> /// Thrown when the provided IEnumerable of Component is null. /// </exception> public static GetAllComponentsDictionaryModelView fromCollectionGroupedByCategory(IEnumerable <Component> components) { if (components == null) { throw new ArgumentNullException(ERROR_NULL_COMPONENT_COLLECTION); } GetAllComponentsDictionaryModelView allComponentsGroupedByCategoryModelView = new GetAllComponentsDictionaryModelView(); foreach (Component component in components) { string categoryName = component.complementaryProduct.productCategory.name; if (!allComponentsGroupedByCategoryModelView.ContainsKey(categoryName)) { allComponentsGroupedByCategoryModelView.Add(categoryName, new GetAllComponentsListModelView()); } GetBasicComponentModelView basicComponentModelView = fromEntityAsBasic(component); allComponentsGroupedByCategoryModelView[categoryName].Add(basicComponentModelView); } return(allComponentsGroupedByCategoryModelView); }
/// <summary> /// Converts an instance of Component into an instance of GetBasicComponentModelView. /// </summary> /// <param name="component">Instance of Component.</param> /// <returns>An instance of GetBasicComponentModelView.</returns> /// <exception cref="System.ArgumentNullException"> /// Thrown when the provided instance of Component is null. /// </exception> public static GetBasicComponentModelView fromEntityAsBasic(Component component) { if (component == null) { throw new ArgumentNullException(ERROR_NULL_COMPONENT); } GetBasicComponentModelView basicComponentModelView = new GetBasicComponentModelView(); basicComponentModelView.productId = component.complementaryProductId; basicComponentModelView.reference = component.complementaryProduct.reference; basicComponentModelView.designation = component.complementaryProduct.designation; basicComponentModelView.modelFilename = component.complementaryProduct.modelFilename; basicComponentModelView.supportsSlots = component.complementaryProduct.supportsSlots; basicComponentModelView.hasComponents = component.complementaryProduct.components.Any(); basicComponentModelView.mandatory = component.mandatory; return(basicComponentModelView); }