Пример #1
0
 private void ProductReferenceIsValid(string productReference, ValidationOutput validationOutput)
 {
     if (productReference == null)
     {
         validationOutput.AddError("Product's reference", "Product's reference is missing!");
     }
 }
Пример #2
0
        private void ValidateMaterial(ChildConfiguredProductDto configuredDto, ValidationOutput validationOutput)
        {
            var material = _materialRepository.GetByReference(configuredDto.ConfiguredMaterial.OriginMaterialReference);

            if (!material.ChosenColorIsValid(configuredDto.ConfiguredMaterial.ColorReference))
            {
                validationOutput.AddError("Chosen Color", "Material does not support the chosen color!");
            }
            Price finishPrice = material.ChosenFinishIsValid(configuredDto.ConfiguredMaterial.FinishReference);

            if (finishPrice == null)
            {
                validationOutput.AddError("Chosen Finish", "Material does not support the chosen finish!");
            }
            else
            {
                validationOutput.DesiredReturn = new Price[] { material.CurrentPrice(), finishPrice };
            }
        }
Пример #3
0
 private void ConfiguredDimensionDtoIsValid(ConfiguredDimensionDto dto, ValidationOutput validationOutput)
 {
     if (dto == null)
     {
         validationOutput.AddError("Dimensions", "Dimensions are missing!");
         return;
     }
     if (dto.Depth <= 0)
     {
         validationOutput.AddError("Depth", "Depth is less or equals to 0");
     }
     if (dto.Height <= 0)
     {
         validationOutput.AddError("Height", "Height is less or equals to 0");
     }
     if (dto.Width <= 0)
     {
         validationOutput.AddError("Width", "Width is less or equals to 0");
     }
 }
Пример #4
0
 private void ConfiguredMaterialDtoIsValid(ConfiguredMaterialDto dto, ValidationOutput validationOutput)
 {
     if (dto == null)
     {
         validationOutput.AddError("Material", "Material is missing!");
         return;
     }
     if (dto.OriginMaterialReference == null)
     {
         validationOutput.AddError("Material's reference", "Material's reference is missing!");
     }
     if (dto.ColorReference == null)
     {
         validationOutput.AddError("Color", "Color is missing!");
         return;
     }
     if (dto.ColorReference == null)
     {
         validationOutput.AddError("Color's reference", "Color's reference is missing!");
     }
     if (dto.FinishReference == null)
     {
         validationOutput.AddError("Finish", "Finish is missing!");
         return;
     }
     if (dto.FinishReference == null)
     {
         validationOutput.AddError("Finish's reference", "Finish's reference is missing!");
     }
 }
Пример #5
0
        private void ValidateSlotDefinition(Product product, ChildConfiguredProductDto configuredDto, ValidationOutput validationOutput)
        {
            Category category = _categoryRepository.GetByReference(product.CategoryReference);

            if (category.IsExternal && configuredDto.SlotReference == null)
            {
                return;
            }
            if (product.SlotDefinition != null)
            {
                if (configuredDto.ConfiguredSlots == null || configuredDto.ConfiguredSlots.Count < 1)
                {
                    validationOutput.AddError("Slots", "Configured Slots required");
                    return;
                }
                var           sum        = 0;
                List <string> references = new List <string>();
                foreach (var slot in configuredDto.ConfiguredSlots)
                {
                    if (!(slot.Size >= product.SlotDefinition.MinSize && slot.Size <= product.SlotDefinition.MaxSize))
                    {
                        validationOutput.AddError("Slot Size", "Slot Size (" + slot.Size + ") is not between min size (" + product.SlotDefinition.MinSize + ") and max size (" + product.SlotDefinition.MaxSize + ")!");
                        return;
                    }
                    if (references.Contains(slot.Reference))
                    {
                        validationOutput.AddError("Slot Reference", "Slot Reference repeated");
                        return;
                    }
                    references.Add(slot.Reference);
                    sum += slot.Size;
                }
                if (sum != configuredDto.ConfiguredDimension.Width)
                {
                    validationOutput.AddError("Sum of Slot Sizes", "The sum of Slot Sizes is not equal to configured dimension width!");
                }
            }
        }
Пример #6
0
        private void ChildrenFits(string slotReference, ConfiguredProduct parent, ConfiguredProductDto childDto, ValidationOutput validationOutput)
        {
            Product  product  = _productRepository.GetByReference(childDto.ProductReference);
            Category category = _categoryRepository.GetByReference(product.CategoryReference);

            if (!category.IsExternal)
            {
                if (!ChildrenHeightFits(slotReference, parent, childDto))
                {
                    validationOutput.AddError("Configured Product's height", "Parent Configured Product's height is insufficient!");
                }
                if (!ChildrenWidthFits(slotReference, parent, childDto))
                {
                    validationOutput.AddError("Configured Product's width", "Parent Configured Product's width is insufficient!");
                }
            }
            else if (category.IsExternal)
            {
                if (!(parent.ConfiguredDimension.Height >= childDto.ConfiguredDimension.Height))
                {
                    validationOutput.AddError("Configured Product's height", "Parent Configured Product's height is insufficient!");
                }

                if (slotReference != null)
                {
                    if (!(SlotDoorFits(slotReference, childDto, parent)))
                    {
                        validationOutput.AddError("Configured Product's width",
                                                  "Parent Configured Product's width is insufficient!");
                    }
                }
                else
                {
                    if (!(SlideDoorFits(childDto, parent)))
                    {
                        validationOutput.AddError("Configured Product's width", "Parent Configured Product's width is insufficient!");
                    }
                }
            }
            if (!ChildrenDepthFits(slotReference, parent, childDto))
            {
                validationOutput.AddError("Configured Product's depth", "Parent Configured Product's depth is insufficient!");
            }
        }
        /**
         * Validations performed:
         *
         * 1. The received list has 1 or more elements.
         * FOREACH RECEIVED ConfiguredProductReference {
         * 2. Validation of each configured product reference (database);
         * 3. Validation of the existence of each configured product (represented by a reference) received, in the collection with the passed reference
         * 4. Validation for duplication between each configured product reference received
         * }
         */

        // ============ Methods to CREATE something ============

        /**
         * Method that will validate and create a new collection in the database.
         *
         * Validations performed:
         * 1. Validation of the new collection's reference (business rules);
         * 2. Validation of the new collection's reference (database);
         * 3. Validation of the received info. (name, description, configured products) (business rules)
         * 4. The received list has 1 or more elements.
         * FOREACH RECEIVED ConfiguredProductReference {
         * 5. Validation of each configured product reference (database);
         * 6. Validation for duplication between each configured product reference received
         * }
         */
        public ValidationOutput Register(CollectionDto dto)
        {
            //1.
            ValidationOutput validationOutput = _collectionDTOValidator.DTOReferenceIsValid(dto.Reference);

            if (validationOutput.HasErrors())
            {
                return(validationOutput);
            }

            //2.
            if (CollectionExists(dto.Reference))
            {
                validationOutput.AddError("Reference of collection", "A collection with the reference '" + dto.Reference + "' already exists in the system!");
                return(validationOutput);
            }

            //3.
            validationOutput = _collectionDTOValidator.DTOIsValidForRegister(dto);
            if (validationOutput.HasErrors())
            {
                return(validationOutput);
            }

            //4.
            validationOutput = new ValidationOutputBadRequest();

            /*if (dto.ProductCollectionList.Count == 0)
             * {
             *  validationOutput.AddError("Selected configured products", "No configured products were selected!");
             *  return validationOutput;
             * }*/
            if (dto.ProductCollectionList.Count > 0)
            {
                List <string> configuredProductReferenceListToAdd = new List <string>();

                foreach (var productCollectionDto in dto.ProductCollectionList)
                {
                    string configuredProductReference =
                        productCollectionDto.ConfiguredProductReference; //Just to simplify the code

                    //5.
                    if (!ConfiguredProductExists(configuredProductReference))
                    {
                        validationOutput.AddError("Reference of configured product",
                                                  "No configured product with the reference '" + configuredProductReference +
                                                  "' exists in the system.");
                        return(validationOutput);
                    }

                    //6.
                    if (configuredProductReferenceListToAdd.Contains(configuredProductReference))
                    {
                        validationOutput.AddError("Configured product",
                                                  "Configured product '" + configuredProductReference +
                                                  "' is duplicated in the list of configured product selected!");
                        return(validationOutput);
                    }

                    configuredProductReferenceListToAdd.Add(configuredProductReference);
                }
            }

            Collection collectionToRegister = _mapper.Map <Collection>(dto);

            validationOutput.DesiredReturn = _mapper.Map <CollectionDto>(_collectionRepository.Add(collectionToRegister));

            return(validationOutput);
        }