Exemple #1
0
        public Specification FindSpecification(int id)
        {
            Specification findSpecification = _specificationRepository.FindSpecification(id);

            if (findSpecification != null)
            {
                return(findSpecification);
            }
            else
            {
                throw new ArgumentException($"Specification with Id: {id} was not found");
            }
        }
Exemple #2
0
        public Product InsertCar(Product product, List <Specification> specifications)
        {
            CheckRequiredSpecificationTypes(specifications);

            List <Specification> updatedSpecifications = new List <Specification>();

            foreach (Specification specification in specifications)
            {
                Specification findSpecification =
                    _specificationRepository.FindSpecification(specification.SpecificationTypeId, specification.Value);

                // if specification exist: add to updated list
                if (findSpecification != null)
                {
                    updatedSpecifications.Add(findSpecification);
                }
                // if specification does not exist: insert specification and add to updated list
                else
                {
                    specification.SpecificationType =
                        _specificationTypeRepository.FindSpecificationType(specification.SpecificationTypeId);

                    int newSpecificationId = _specificationRepository.InsertSpecification(specification);

                    Specification insertedSpecification = specification;
                    insertedSpecification.Id = newSpecificationId;

                    updatedSpecifications.Add(insertedSpecification);
                }
            }

            List <Category> categories = new List <Category>();
            Category        car        = _categoryRepository.FindCategory("Cars");

            categories.Add(car);

            _carRepository.InsertCar(product, categories, updatedSpecifications);

            return(_carRepository.FindCar(product.Name));
        }