public override ValidationOutput DTOIsValidForUpdate(FinishDto consideredDto)
        {
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            if (!ReferenceIsValid(consideredDto.Reference))
            {
                validationOutput.AddError("Reference of finish", "New reference '" + consideredDto.Reference + "' is invalid!");
            }
            if (!NameIsValid(consideredDto.Name))
            {
                validationOutput.AddError("Name of finish", "New name '" + consideredDto.Name + "' is invalid!");
            }
            if (!DescriptionIsValid(consideredDto.Description))
            {
                validationOutput.AddError("Description of finish", "New description '" + consideredDto.Description + "' is invalid!");
            }
            if (consideredDto.Price != null)
            {
                ValidationOutput priceDTOValidationOutput = _priceDTOValidator.DTOIsValid(consideredDto.Price);
                if (priceDTOValidationOutput.HasErrors())
                {
                    priceDTOValidationOutput.AppendToAllkeys("Finish '" + consideredDto.Reference + "' | ");
                    validationOutput.Join(priceDTOValidationOutput);
                }
            }
            else
            {
                validationOutput.AddError("Price of finish", "The price has can not be null!");
            }
            return(validationOutput);
        }
        public override ValidationOutput DTOIsValid(ModelGroupDto consideredDto)
        {
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            if (!RelativeURLIsValid(consideredDto.RelativeURL))
            {
                validationOutput.AddError("RelativeURL", "URL to OBJ file is invalid!");
                return(validationOutput);
            }
            var components = consideredDto.Components;

            if (!(components.Count > 0))
            {
                validationOutput.AddError("Components", "There are no components");
                return(validationOutput);
            }
            foreach (var component in components)
            {
                validationOutput = _componentDTOValidator.DTOIsValid(component);
                if (validationOutput.HasErrors())
                {
                    return(validationOutput);
                }
            }
            return(validationOutput);
        }
        public override ValidationOutput DTOIsValidForRegister(CategoryDto consideredDto)
        {
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            if (consideredDto.IsExternal != null)
            {
                if (!IsExternalIsValid(consideredDto.IsExternal))
                {
                    validationOutput.AddError("Verification of category", "The is external verification'" + consideredDto.IsExternal + "' is not valid!");
                }
            }
            if (!NameIsValid(consideredDto.Name))
            {
                validationOutput.AddError("Name of category", "The name'" + consideredDto.Name + "' is not valid!");
            }
            if (!DescriptionIsValid(consideredDto.Description))
            {
                validationOutput.AddError("Description of category", "The description'" + consideredDto.Description + "' is not valid!");
            }
            if (!ParentCategoryReferenceIsValid(consideredDto.ParentCategoryReference))
            {
                validationOutput.AddError("Parent category reference of category", "The parent category reference '" + consideredDto.ParentCategoryReference + "' is not valid!");
            }
            return(validationOutput);
        }
        public override ValidationOutput DTOIsValid(AlgorithmDto consideredDto)
        {
            if (consideredDto is MaterialFinishPartAlgorithmDto)
            {
                return(new ValidationOutputBadRequest());
            }
            if (consideredDto is MaterialPartAlgorithmDto)
            {
                return(new ValidationOutputBadRequest());
            }
            if (consideredDto is RatioAlgorithmDto)
            {
                return(_ratioAlgorithmDTOValidator.DTOIsValid((RatioAlgorithmDto)consideredDto));
            }
            if (consideredDto is SizePartAlgorithmDto)
            {
                return(new ValidationOutputBadRequest());
            }
            if (consideredDto is SizePercentagePartAlgorithmDto)
            {
                return(_sizePercentagePartAlgorithmDTOValidator.DTOIsValid((SizePercentagePartAlgorithmDto)consideredDto));
            }
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            validationOutput.AddError("Inputed algorithm", "Algorithm not recongized.");
            return(validationOutput);
        }
        /**
         * Method that will add new configured products to the collection with the passed reference.
         * It is assumed that a list with 1 or more objects is received.
         *
         * Validations performed:
         * 1. Validation of the passed collection's reference (database);
         * 2. The received list has 1 or more elements.
         * FOREACH RECEIVED string (Configured Product reference) {
         * 3. Validation of current configured product reference (database);
         * 4. Validation of the existence of current configured product in the collection with the passed reference
         * 5. Validation for duplication between each configured product reference received
         */
        public ValidationOutput AddConfiguredProducts(string reference, IEnumerable <ConfiguredProductDto> enumerableConfiguredProduct)
        {
            //1.
            ValidationOutput validationOutput = new ValidationOutputNotFound();

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

            Collection collectionToModify = _collectionRepository.GetByReference(reference);

            List <ConfiguredProductDto> configuredProductList = new List <ConfiguredProductDto>(enumerableConfiguredProduct);

            //2.
            validationOutput = new ValidationOutputBadRequest();
            if (configuredProductList.Count == 0)
            {
                validationOutput.AddError("Selected configured products", "No configured products were selected!");
                return(validationOutput);
            }

            List <string> configuredProductListToAdd = new List <string>();

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

                //4.
                if (collectionToModify.ConfiguredProductIsInCollection(configuredProduct.Reference))
                {
                    validationOutput.AddError("Configured product", "Configured product '" + configuredProduct.Reference + "' already belongs to collection with reference '" + reference + "'.");
                    return(validationOutput);
                }

                //5.
                if (configuredProductListToAdd.Contains(configuredProduct.Reference))
                {
                    validationOutput.AddError("Configured product", "Configured product '" + configuredProduct.Reference + "' is duplicated in the list of configured product selected!");
                    return(validationOutput);
                }

                configuredProductListToAdd.Add(configuredProduct.Reference);
            }

            foreach (var configuredProductToAdd in configuredProductListToAdd)
            {
                collectionToModify.AddConfiguredProduct(configuredProductToAdd);
            }

            validationOutput.DesiredReturn = configuredProductListToAdd;
            _collectionRepository.Update(collectionToModify);
            return(validationOutput);
        }
Esempio n. 6
0
        public override ValidationOutput DTOIsValid(RatioAlgorithmDto consideredDto)
        {
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            if (consideredDto == null)
            {
                validationOutput.AddError("Ratio algorithm", "Null.");
                return(validationOutput);
            }

            if (!ValueDescIsValid(consideredDto.FirstValueDesc))
            {
                validationOutput.AddError("Ratio algorithm's First Value", "Inputed value description '" + consideredDto.FirstValueDesc + "' is not valid!");
            }

            if (!ValueDescIsValid(consideredDto.SecondValueDesc))
            {
                validationOutput.AddError("Ratio algorithm's Second Value", "Inputed value description '" + consideredDto.SecondValueDesc + "' is not valid!");
            }

            if (!OperatorIsValid(consideredDto.Operator))
            {
                validationOutput.AddError("Ratio algorithm's Operator", "Inputed operator '" + consideredDto.Operator + "' is not valid!");
            }

            if (!RatioIsValid(consideredDto.Ratio))
            {
                validationOutput.AddError("Ratio algorithm's Ratio", "Inputed ratio '" + consideredDto.Ratio + "' is not valid!");
            }

            return(validationOutput);
        }
Esempio n. 7
0
        public ValidationOutput PossibleWidthsIsValid(DimensionValuesDto consideredDto)
        {
            ValidationOutput validationOutput = new ValidationOutputBadRequest();
            List <ValuesDto> possibleWidths   = new List <ValuesDto>();

            foreach (var setOfValuesDto in consideredDto.PossibleWidths)
            {
                ValidationOutput eachValueValidationOutput = _valuesDTOValidator.DTOIsValid(setOfValuesDto);
                if (eachValueValidationOutput.HasErrors())
                {
                    validationOutput.Join(eachValueValidationOutput);
                    return(validationOutput);
                }

                validationOutput = new ValidationOutputBadRequest();
                if (possibleWidths.Contains(setOfValuesDto))
                {
                    if (setOfValuesDto is ContinuousValueDto)
                    {
                        ContinuousValueDto temp = (ContinuousValueDto)setOfValuesDto;
                        validationOutput.AddError("Dimension's widths", "The width interval [" + temp.MinValue + ", " + temp.MaxValue + "] is duplicated in the list of possible widths.");
                    }
                    if (setOfValuesDto is DiscreteValueDto)
                    {
                        validationOutput.AddError("Dimension's widths", "The width '" + setOfValuesDto + "' is duplicated in the list of possible widths.");
                    }
                    return(validationOutput);
                }

                possibleWidths.Add(setOfValuesDto);
            }
            return(validationOutput);
        }
        public override ValidationOutput DTOIsValidForUpdate(MaterialDto consideredDto)
        {
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            if (consideredDto.Name != null)
            {
                if (!NameIsValid(consideredDto.Name))
                {
                    validationOutput.AddError("Name of material", "New name'" + consideredDto.Name + "' is not valid!");
                }
            }

            if (consideredDto.Description != null)
            {
                if (!DescriptionIsValid(consideredDto.Description))
                {
                    validationOutput.AddError("Description of material",
                                              "New description'" + consideredDto.Description + "' is not valid!");
                }
            }

            if (consideredDto.Price != null)
            {
                ValidationOutput priceDTOValidationOutput = _priceDTOValidator.DTOIsValid(consideredDto.Price);
                if (priceDTOValidationOutput.HasErrors())
                {
                    priceDTOValidationOutput.AppendToAllkeys("Material '" + consideredDto.Reference + "' > ");
                    validationOutput.Join(priceDTOValidationOutput);
                }
            }
            return(validationOutput);
        }
Esempio n. 9
0
        // ============ Methods to CREATE something ============

        /**
         * Method that will validate and create a new material in the database.
         *
         * Validations performed:
         * 1. Validation of the new material's reference (business rules);
         * 2. Validation of the new material's reference (database);
         * 3. Validation of the received info. (name, description, colors, finishes) (business rules)
         */
        public ValidationOutput Register(MaterialDto dto)
        {
            //1.
            ValidationOutput validationOutput = _materialDTOValidator.DTOReferenceIsValid(dto.Reference);

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

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

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

            if (dto.Colors.Count > 0)
            {
                validationOutput = PrivateAddColorsWithMaterial(dto.Colors);
                if (validationOutput.HasErrors())
                {
                    return(validationOutput);
                }
            }

            if (dto.Finishes.Count > 0)
            {
                validationOutput = PrivateAddFinishesWithMaterial(dto.Finishes);
                if (validationOutput.HasErrors())
                {
                    return(validationOutput);
                }
            }

            //NOTA: Ainda que este método verifique se o atributo Price é != null, nós, aqui no Register, nunca deixamos que seja null devido às validações
            AddNewPriceToMaterialHistory(dto);

            foreach (var finish in dto.Finishes)
            {
                finish.IsActive = true;
            }

            //If we reached here then that means we can add the new material
            validationOutput.DesiredReturn =
                _mapper.Map <MaterialDto>(
                    _materialRepository.Add(_mapper.Map <Material>(dto)));
            return(validationOutput);
        }
Esempio n. 10
0
        /**
         * Validations performed:
         *
         * 1. The received list has 1 or more elements.
         * FOREACH RECEIVED Color{
         * 2. Validation of each color's definition (business rules);
         * 3. Validation of the existence of each Color received, in the material with the passed reference
         * 4. Validation for duplication between received colors
         * }
         */
        private ValidationOutput PrivateAddColorsWithMaterial(IEnumerable <ColorDto> enumerableColorDto)
        {
            List <ColorDto>
            listColorDto =
                new List <ColorDto>(
                    enumerableColorDto);     //Since we receive an IEnumerable, we need to have something concrete

            //1.
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            if (listColorDto.Count == 0)
            {
                validationOutput.AddError("Selected colors", "No colors were selected!");
                return(validationOutput);
            }

            List <ColorDto> colorsToAdd = new List <ColorDto>();

            foreach (var currentColorDto in listColorDto)
            {
                validationOutput = new ValidationOutputBadRequest();

                //2.
                validationOutput = _colorDTOValidator.DTOReferenceIsValid(currentColorDto.HexCode);
                if (validationOutput.HasErrors())
                {
                    return(validationOutput);
                }

                validationOutput = _colorDTOValidator.DTOIsValid(currentColorDto);
                if (validationOutput.HasErrors())
                {
                    return(validationOutput);
                }

                //3.
                validationOutput = _colorDTOValidator.DTOIsValidForRegister(currentColorDto);
                if (validationOutput.HasErrors())
                {
                    return(validationOutput);
                }

                //4.
                if (colorsToAdd.Contains(currentColorDto))
                {
                    validationOutput.AddError("Color",
                                              "Color with the hex code '" + currentColorDto.HexCode +
                                              "' is duplicated in the list of selected colors.");
                    return(validationOutput);
                }

                colorsToAdd.Add(currentColorDto);
            }

            return(validationOutput);
        }
Esempio n. 11
0
        public override ValidationOutput DTOIsValid(DiscreteValueDto consideredDto)
        {
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            if (consideredDto.Value <= 0)
            {
                validationOutput.AddError("Discrete value", " A discrete value is not valid!");
            }
            return(validationOutput);
        }
        public override ValidationOutput DTOIsValid(PriceDto consideredDto)
        {
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            if (!ValueIsValid(consideredDto.Value))
            {
                validationOutput.AddError("Price", "Inputed price is invalid!");
            }
            return(validationOutput);
        }
        public override ValidationOutput DTOReferenceIsValid(string finishReference)
        {
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            if (!ReferenceIsValid(finishReference))
            {
                validationOutput.AddError("Reference of finish", "The reference '" + finishReference + "' is not valid!");
            }
            return(validationOutput);
        }
        public ValidationOutput DTOReferenceIsValid(string colorCode)
        {
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            if (!HexCodeIsValid(colorCode))
            {
                validationOutput.AddError("Hex Code of color", "The hex code '" + colorCode + "' is not valid!");
            }
            return(validationOutput);
        }
Esempio n. 15
0
        public override ValidationOutput DTOReferenceIsValid(string configuredProductReference)
        {
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            if (!ReferenceIsValid(configuredProductReference))
            {
                validationOutput.AddError("Configured product reference", "Configured product reference is invalid!");
            }
            return(validationOutput);
        }
Esempio n. 16
0
        public override ValidationOutput DTOIsValid(ContinuousValueDto consideredDto)
        {
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            if (consideredDto.MinValue <= 0 || consideredDto.MinValue > consideredDto.MaxValue)
            {
                validationOutput.AddError("Continuous value", " A continuous value is not valid!");
            }
            return(validationOutput);
        }
Esempio n. 17
0
        public override ValidationOutput DTOIsValidForUpdate(ProductDto consideredDto)
        {
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            if (consideredDto.Name != null)
            {
                if (!NameIsValid(consideredDto.Name))
                {
                    validationOutput.AddError("Name of product", "New name '" + consideredDto.Name + "' is not valid!");
                }
            }

            if (consideredDto.Description != null)
            {
                if (!DescriptionIsValid(consideredDto.Description))
                {
                    validationOutput.AddError("Description of product",
                                              "New description '" + consideredDto.Description + "' is not valid!");
                }
            }

            if (consideredDto.Price != null)
            {
                ValidationOutput priceDTOValidationOutput = _priceDTOValidator.DTOIsValid(consideredDto.Price);
                if (priceDTOValidationOutput.HasErrors())
                {
                    priceDTOValidationOutput.AppendToAllkeys("Product '" + consideredDto.Reference + "' > ");
                    validationOutput.Join(priceDTOValidationOutput);
                }
            }

            if (consideredDto.SlotDefinition != null)
            {
                ValidationOutput slotDefinitionDTOValidationOutput =
                    _slotDefinitionDTOValidator.DTOIsValid(consideredDto.SlotDefinition);
                if (slotDefinitionDTOValidationOutput.HasErrors())
                {
                    slotDefinitionDTOValidationOutput.AppendToAllkeys("Product '" + consideredDto.Reference + "' > ");
                    validationOutput.Join(slotDefinitionDTOValidationOutput);
                }
            }

            var modelGroup = consideredDto.ModelGroup;

            if (modelGroup != null)
            {
                ValidationOutput modelGroupValidationOutput = _modelGroupDTOValidator.DTOIsValid(modelGroup);
                if (validationOutput.HasErrors())
                {
                    validationOutput.Join(modelGroupValidationOutput);
                }
            }

            return(validationOutput);
        }
Esempio n. 18
0
        /**
         * Method that will delete configured products, that belong to a certain, existing collection, (in the form of ProductCollection objects) from the catalog with the passed reference.
         * It is assumed that a list with 1 or more objects is received.
         *
         * Validations performed:
         * 1. Validation of the passed catalog's reference (database);
         * 2. The received list has 1 or more elements.
         * FOREACH RECEIVED ProductCollection {
         * 3. Validation of the existence of current ProductCollection received, in the catalog with the passed reference
         * 4. Validation for duplication between each ProductCollection received
         * }
         */
        public ValidationOutput DeleteVariousProductCollection(string reference, IEnumerable <ProductCollectionDto> enumerableProductCollectionDto)
        {
            //1.
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            if (!CatalogExists(reference))
            {
                validationOutput.AddError("Reference of catalog", "No catalog with the '" + reference + "' exists in the system!");
                return(validationOutput);
            }

            Catalog catalogToModify = _catalogRepository.GetByReference(reference);

            List <ProductCollectionDto> productCollectionDtoList = new List <ProductCollectionDto>(enumerableProductCollectionDto);

            //2.
            validationOutput = new ValidationOutputBadRequest();
            if (productCollectionDtoList.Count == 0)
            {
                validationOutput.AddError("Selected 'configured product - collection' items", "No 'configured product - collection' items were selected!");
                return(validationOutput);
            }

            List <ProductCollection> productCollectionListToRemove = new List <ProductCollection>();

            foreach (var currentProductCollectionDto in productCollectionDtoList)
            {
                ProductCollection currentProdCollection = _mapper.Map <ProductCollection>(currentProductCollectionDto);

                //3.
                if (!catalogToModify.ContainsProductCollection(currentProdCollection))
                {
                    validationOutput.AddError("'Configured product - collection' item", "'Configured product - collection' item with configured product '" + currentProdCollection.ConfiguredProductReference + "' that is associated with the collection '" + currentProdCollection.CollectionReference + "' does not belong to catalog with reference '" + reference + "'");
                    return(validationOutput);
                }

                //4.
                if (productCollectionListToRemove.Contains(currentProdCollection))
                {
                    validationOutput.AddError("'Configured product - collection' item", "'Configured product - collection' item with configured product '" + currentProdCollection.ConfiguredProductReference + "' that is associated with the collection '" + currentProdCollection.CollectionReference + "' is duplicated in the list of 'configured product - collection' items selected!");
                    return(validationOutput);
                }

                productCollectionListToRemove.Add(currentProdCollection);
            }

            foreach (var productCollectionToRemove in productCollectionListToRemove)
            {
                catalogToModify.RemoveProductCollection(productCollectionToRemove);
            }

            _catalogRepository.Update(catalogToModify);
            return(validationOutput);
        }
Esempio n. 19
0
        public override ValidationOutput DTOIsValid(SizePercentagePartAlgorithmDto consideredDto)
        {
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            if (consideredDto.Min <= 0 || consideredDto.Max <= 0 || consideredDto.Min > 100 || consideredDto.Max > 100 || consideredDto.Max < consideredDto.Min ||
                (!string.Equals(consideredDto.SizeType, "height", StringComparison.Ordinal) && !string.Equals(consideredDto.SizeType, "depth", StringComparison.Ordinal) && !string.Equals(consideredDto.SizeType, "width", StringComparison.Ordinal)))
            {
                validationOutput.AddError("SizePercentagePart's attribute", "SizePercentagePart's attribute not valid!");
            }
            return(validationOutput);
        }
        public override ValidationOutput DTOIsValid(PriceHistoryDto consideredDto)
        {
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            if (consideredDto.Date < DateTime.Now)
            {
                validationOutput.AddError("Price history item", "A price history item has a date that has already passed.");
                return(validationOutput);
            }
            return(validationOutput);
        }
Esempio n. 21
0
        public override ValidationOutput DTOReferenceIsValid(string materialReference)
        {
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            if (!ReferenceIsValid(materialReference))
            {
                validationOutput.AddError("Reference of product",
                                          "The reference '" + materialReference + "' is not valid!");
            }

            return(validationOutput);
        }
Esempio n. 22
0
        /**
         * Validations performed:
         *
         * 1. The received list has 1 or more elements.
         * FOREACH FINISH RECEIVED {
         * 2. Validation of each finish's reference (business rules);
         * 3. Validation of each finish's definition (business rules);
         * 4. Validation of the existence of each finish received, in the material with the passed reference.
         * 5. Validation for duplication between received finishes.
         * }
         */
        private ValidationOutput PrivateAddFinishesWithMaterial(IEnumerable <FinishDto> enumerableFinishDto)
        {
            List <FinishDto>
            listFinishDto =
                new List <FinishDto>(
                    enumerableFinishDto);     //Since we receive an IEnumerable, we need to have something concrete

            //1.
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            if (listFinishDto.Count == 0)
            {
                validationOutput.AddError("Finishes selected", "No finishes were selected!");
                return(validationOutput);
            }

            List <FinishDto> finishesToAdd = new List <FinishDto>();

            foreach (var currentFinishDto in listFinishDto)
            {
                validationOutput = new ValidationOutputBadRequest();

                //2.
                validationOutput = _finishDTOValidator.DTOReferenceIsValid(currentFinishDto.Reference);
                if (validationOutput.HasErrors())
                {
                    return(validationOutput);
                }

                //3.
                validationOutput = _finishDTOValidator.DTOIsValidForRegister(currentFinishDto);
                if (validationOutput.HasErrors())
                {
                    return(validationOutput);
                }

                //5.
                if (finishesToAdd.Contains(currentFinishDto))
                {
                    validationOutput.AddError("Finish",
                                              "Finish with the reference '" + currentFinishDto.Reference +
                                              "' is duplicated in the list of selected finishes.");
                    return(validationOutput);
                }

                AddNewPriceToFinishHistory(currentFinishDto);
                finishesToAdd.Add(currentFinishDto);
            }

            return(validationOutput);
        }
        public ValidationOutput DTOIsValidForRegister(ColorDto consideredDto)
        {
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            if (!NameIsValid(consideredDto.Name))
            {
                validationOutput.AddError("Name of color", "The name'" + consideredDto.Name + "' is not valid!");
            }
            if (!HexCodeIsValid(consideredDto.HexCode))
            {
                validationOutput.AddError("Hex Code of color", "The hex code'" + consideredDto.HexCode + "' is not valid!");
            }
            return(validationOutput);
        }
        public override ValidationOutput DTOIsValid(SlotDefinitionDto consideredDto)
        {
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            if (consideredDto != null && (consideredDto.MinSize <= 0 || consideredDto.MaxSize <= 0 ||
                                          consideredDto.MaxSize < consideredDto.MinSize ||
                                          consideredDto.RecSize > consideredDto.MaxSize ||
                                          consideredDto.RecSize < consideredDto.MinSize))
            {
                validationOutput.AddError("Slot definition", "The slot definition is not valid!");
            }

            return(validationOutput);
        }
Esempio n. 25
0
        public override ValidationOutput DTOIsValidForRegister(ConfiguredProductDto consideredDto)
        {
            /* foreach(var part in dto.Parts){
             *  if(!part.ModeRestrictionIsValid(part.ModelRestriction)){
             *      return false;
             *  }
             * }*/
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            ConfiguredMaterialDtoIsValid(consideredDto.ConfiguredMaterial, validationOutput);
            ConfiguredDimensionDtoIsValid(consideredDto.ConfiguredDimension, validationOutput);
            ProductReferenceIsValid(consideredDto.ProductReference, validationOutput);
            return(validationOutput);
        }
        public override ValidationOutput DTOIsValidForUpdate(CollectionDto consideredDto)
        {
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            if (!NameIsValid(consideredDto.Name))
            {
                validationOutput.AddError("Name of collection", "New name'" + consideredDto.Name + "' is not valid!");
            }
            if (!DescriptionIsValid(consideredDto.Description))
            {
                validationOutput.AddError("Description of collection", "New description'" + consideredDto.Description + "' is not valid!");
            }
            return(validationOutput);
        }
Esempio n. 27
0
        private ValidationOutput ValidateConfiguredProduct(ChildConfiguredProductDto configuredDto)
        {
            ValidationOutput validationOutput = new ValidationOutputBadRequest();
            var product = _productRepository.GetByReference(configuredDto.ProductReference);

            if (!product.ChosenDimensionDtoIsValid(configuredDto.ConfiguredDimension))
            {
                validationOutput.AddError("Configured Product's dimension", "Chosen Dimension does not belong to any possible dimension");
                return(validationOutput);
            }

            if (!product.ConfiguredMaterialDtoExists(configuredDto.ConfiguredMaterial))
            {
                validationOutput.AddError("Configured Material's reference", "Product does not support the chosen material");
                return(validationOutput);
            }

            ValidateMaterial(configuredDto, validationOutput);
            if (validationOutput.HasErrors())
            {
                return(validationOutput);
            }

            ValidateSlotDefinition(product, configuredDto, validationOutput);
            if (validationOutput.HasErrors())
            {
                return(validationOutput);
            }

            var parentConfiguredProduct = _configuredProductRepository.GetByReference(configuredDto.ParentReference);

            if (parentConfiguredProduct != null)
            {
                ChildrenFits(configuredDto.SlotReference, parentConfiguredProduct, configuredDto, validationOutput);
                if (validationOutput.HasErrors())
                {
                    return(validationOutput);
                }
            }

            if (!ObeysRestrictions(configuredDto))
            {
                validationOutput.AddError("Restriction", "Configured Product does not obey to defined restrictions!");
            }
            validationOutput.DesiredReturn = new Price[] { product.Price, ((Price[])validationOutput.DesiredReturn)[1], ((Price[])validationOutput.DesiredReturn)[0] };
            return(validationOutput);
        }
Esempio n. 28
0
        public override ValidationOutput DTOIsValid(DimensionValuesDto consideredDto)
        {
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            if (string.IsNullOrEmpty(consideredDto.Reference))
            {
                validationOutput.AddError("Dimension's Reference", "There is no reference.");
                return(validationOutput);
            }

            //================== PossibleHeights attribute ==================
            if (consideredDto.PossibleHeights == null || consideredDto.PossibleHeights.Count <= 0)
            {
                validationOutput.AddError("Dimension's heights", "There are no heights.");
                return(validationOutput);
            }

            validationOutput = this.PossibleHeightsIsValid(consideredDto);
            if (validationOutput.HasErrors())
            {
                return(validationOutput);
            }

            //================== PossibleWidths attribute ==================
            if (consideredDto.PossibleWidths == null || consideredDto.PossibleWidths.Count <= 0)
            {
                validationOutput.AddError("Dimension's widths", "There are no widths.");
                return(validationOutput);
            }

            validationOutput = this.PossibleWidthsIsValid(consideredDto);
            if (validationOutput.HasErrors())
            {
                return(validationOutput);
            }

            //================== PossibleDepths attribute ==================
            if (consideredDto.PossibleDepths == null || consideredDto.PossibleDepths.Count <= 0)
            {
                validationOutput.AddError("Dimension's depths", "There are no depths");
                return(validationOutput);
            }
            validationOutput = this.PossibleDepthsIsValid(consideredDto);

            return(validationOutput);
        }
        // ============ Methods to CREATE something ============

        /**
         * Method that will validate and create a new category in the database.
         *
         * Validations performed:
         * 1. Validation of the new category's reference (business rules);
         * 2. Validation of the new category's reference (database);
         * 3. Validation of the received info. (name, description, parent category) (business rules)
         * 4. Validation of the category's parent category reference (database)
         */
        public ValidationOutput Register(CategoryDto dto)
        {
            //1.
            ValidationOutput validationOutput = _categoryDTOValidator.DTOReferenceIsValid(dto.Reference);

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

            //2.
            validationOutput = new ValidationOutputBadRequest();
            if (Exists(dto.Reference))
            {
                validationOutput.AddError("Category's reference",
                                          "A category with the reference '" + dto.Reference + "' already exists in the system!");
                return(validationOutput);
            }

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

            //4.
            validationOutput = new ValidationOutputNotFound();
            if (!string.IsNullOrEmpty(dto.ParentCategoryReference))
            {
                if (!Exists(dto.ParentCategoryReference))
                {
                    validationOutput.AddError("Category's parent category reference",
                                              "No category with the reference '" + dto.ParentCategoryReference + "' exists in the system.");
                    return(validationOutput);
                }
            }

            //If we reached here than that means we can add the new category
            Category passedCategory = _mapper.Map <Category>(dto);

            validationOutput.DesiredReturn = _mapper.Map <CategoryDto>(_categoryRepository.Add(passedCategory));

            return(validationOutput);
        }
        public ValidationOutput DTOIsValidForUpdate(ColorDto consideredDto)
        {
            ValidationOutput validationOutput = new ValidationOutputBadRequest();

            if (!NameIsValid(consideredDto.Name))
            {
                validationOutput.AddError("Name of color", "New name'" + consideredDto.Name + "' is not valid!");
            }
            if (!DescriptionIsValid(consideredDto.Description))
            {
                validationOutput.AddError("Description of color", "New description'" + consideredDto.Description + "' is not valid!");
            }
            if (!HexCodeIsValid(consideredDto.HexCode))
            {
                validationOutput.AddError("Hex Code", "The hex code '" + consideredDto.HexCode + "' is not valid!");
            }
            return(validationOutput);
        }