Beispiel #1
0
        /// <summary>
        /// Creates a new instance of CustomizedMaterial.
        /// </summary>
        /// <param name="addCustomizedMaterialModelView">AddCustomizedMaterialModelView representing the CustomizedMaterial's data.</param>
        /// <returns>An instance of CustomizedMaterial.</returns>
        /// <exception cref="System.ArgumentException">Thrown when no Material could be found with the provided identifier.</exception>
        public static CustomizedMaterial create(AddCustomizedMaterialModelView addCustomizedMaterialModelView)
        {
            MaterialRepository materialRepository = PersistenceContext.repositories().createMaterialRepository();

            Material material = materialRepository.find(addCustomizedMaterialModelView.materialId);

            if (material == null)
            {
                throw new ArgumentException(string.Format(ERROR_UNABLE_TO_FIND_MATERIAL, addCustomizedMaterialModelView.materialId));
            }
            //TODO: replace usage of dto
            FinishDTO finishDTO = addCustomizedMaterialModelView.finish;
            ColorDTO  colorDTO  = addCustomizedMaterialModelView.color;

            if (finishDTO == null && colorDTO == null)
            {
                throw new ArgumentException(NULL_COLOR_AND_FINISH);
            }

            CustomizedMaterial customizedMaterial = null;

            if (finishDTO == null && colorDTO != null)
            {
                customizedMaterial = CustomizedMaterial.valueOf(material, colorDTO.toEntity());
            }
            else if (finishDTO != null && colorDTO == null)
            {
                customizedMaterial = CustomizedMaterial.valueOf(material, finishDTO.toEntity());
            }
            else
            {
                customizedMaterial = CustomizedMaterial.valueOf(material, colorDTO.toEntity(), finishDTO.toEntity());
            }

            return(customizedMaterial);
        }
Beispiel #2
0
        /// <summary>
        /// Add the color of a material from update
        /// </summary>
        /// <param name="idMaterial">id of the material to be updated</param>
        /// <param name="addColorDTO">ColorDTO with the information of color to add</param>
        /// <returns>boolean true if the update was successful, false if not</returns>
        public AddColorModelView addColor(long idMaterial, ColorDTO addColorDTO)
        {
            MaterialRepository materialRepository = PersistenceContext.repositories().createMaterialRepository();
            Material           material           = materialRepository.find(idMaterial);

            if (addColorDTO != null)
            {
                Color colorToAdd = addColorDTO.toEntity();
                material.addColor(colorToAdd);


                materialRepository.update(material);
                AddColorModelView addColorModelView = new AddColorModelView();
                addColorModelView.color = addColorDTO;
                return(addColorModelView);
            }
            return(null);
        }