示例#1
0
        /// <summary>
        /// Add the finish of a material from update
        /// </summary>
        /// <param name="idMaterial">id of the material to be updated</param>
        /// <param name="addFinishDTO">FinishDTO with the information of finish to add</param>
        /// <returns>boolean true if the update was successful, false if not</returns>
        public AddFinishModelView addFinish(long idMaterial, FinishDTO addFinishDTO)
        {
            MaterialRepository materialRepository = PersistenceContext.repositories().createMaterialRepository();
            Material           material           = materialRepository.find(idMaterial);

            if (addFinishDTO != null)
            {
                material.addFinish(addFinishDTO.toEntity());


                materialRepository.update(material);
                AddFinishModelView addFinishModelView = new AddFinishModelView();
                addFinishModelView.finish = addFinishDTO;
                return(addFinishModelView);
            }
            return(null);
        }
示例#2
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);
        }