コード例 #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");
            }
        }
コード例 #2
0
ファイル: CarService.cs プロジェクト: Filip-E/garage-app
        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));
        }