Пример #1
0
 public int InsertSpecification(Specification specification)
 {
     HasRequiredProps(specification, false);
     specification.SpecificationType =
         _specificationTypeRepository.FindSpecificationType(specification.SpecificationTypeId);
     return(_specificationRepository.InsertSpecification(specification));
 }
Пример #2
0
        public int InsertSpecificationType(SpecificationType specificationType)
        {
            hasRequiredProps(specificationType, false);
            SpecificationType findSpecificationType = _repository.FindSpecificationType(specificationType.Type);

            if (findSpecificationType == null)
            {
                _repository.InsertSpecificationType(specificationType);
                return((_repository.FindSpecificationType(specificationType.Type)).Id);
            }
            else
            {
                throw new ArgumentException($"Specification type: {specificationType.Type} already exists");
            }
        }
Пример #3
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));
        }