public IHttpActionResult GetById(Guid productId, Guid id)
        {
            var productOption = _productOptionRepository.GetById(id);

            if (productOption == null)
            {
                return(StatusCode(HttpStatusCode.NotFound));
            }
            return(Ok(productOption));
        }
        /// <summary>
        /// Returns a list of products that belong to the given group.
        /// </summary>
        /// <param name="carModelProductId"></param>
        /// <param name="optionId"></param>
        /// <returns></returns>
        public IEnumerable <CarModelOptionProduct> GetCarModelsOptionProducts(int carModelProductId, int optionId)
        {
            var option = _productOptionRepository.GetById(optionId, carModelProductId);

            if (option == null)
            {
                return(null);
            }

            var products = _productRepository.GetOptionProducts(carModelProductId, optionId)
                           .Select(optionProduct =>
            {
                // Wenn es sich um ein Standard-Produkt handelt, ist der Preis im Preis des Fahrzeugs enthalten
                var grossPrice = option.DefaultProductIds.Contains(optionProduct.Id)
                        ? 0
                        : PriceHelper.GetGrossPrice(optionProduct.NetPrice, optionProduct.VATRate);

                return(new CarModelOptionProduct(optionProduct.EAN, optionProduct.Name,
                                                 optionProduct.Description, grossPrice,
                                                 option.DefaultProductIds != null && option.DefaultProductIds.Contains(optionProduct.Id)));
            })
                           .OrderBy(x => x.Price);

            return(products);
        }
Esempio n. 3
0
        public void Handle(UpdateProductOptionCommand command)
        {
            var product = _productOptionRepository.GetById(command.Id);

            product.Name        = command.Name;
            product.Description = command.Description;

            Commit();
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="productOptionDto"></param>
        /// <returns></returns>
        public async Task <int> AddProductOption(ProductOptionDto productOptionDto)
        {
            ProductOption existingProductOption = productOptionRepository.GetById(productOptionDto.Id);

            if (existingProductOption != null)
            {
                throw new HttpResponseException
                      {
                          Status = 500,
                          Value  = $"Product Option with the same id {productOptionDto.Id} already exists"
                      }
            }
            ;

            return(await productOptionRepository.AddOrUpdateAsync(new ProductOption
            {
                Id = productOptionDto.Id,
                ProductId = productOptionDto.ProductId,
                Name = productOptionDto.Name,
                Description = productOptionDto.Description
            }, true));
        }
Esempio n. 5
0
        public CarOrderDetails AddOrder(CarOrderDetails carOrderDetails)
        {
            var carModelProduct = _productRepository.GetByEAN(carOrderDetails.CarModelEAN);

            if (carModelProduct == null)
            {
                throw new Exception("The product is unknown.");
            }

            var order = new Order(carOrderDetails.Code);

            order.AddPosition(new OrderPosition(
                                  carModelProduct.EAN,
                                  carModelProduct.NetPrice,
                                  carModelProduct.VATRate,
                                  "Basis-Modell: " + carModelProduct.Name));

            foreach (var(optionId, carModelOptionProduct) in carOrderDetails.CarOptionProducts)
            {
                var option = _productOptionRepository.GetById(optionId, carModelProduct.Id);
                if (option == null)
                {
                    throw new Exception("The option with ID " + optionId + " is unknown.");
                }

                var optionProduct = _productRepository.GetByEAN(carModelOptionProduct.EAN);
                if (optionProduct == null)
                {
                    throw new Exception("The product with EAN " + carModelOptionProduct.EAN + " is unknown.");
                }

                order.AddPosition(new OrderPosition(
                                      optionProduct.EAN,
                                      optionProduct.NetPrice,
                                      optionProduct.VATRate,
                                      "Option " + option.Name + ": " + optionProduct.Name));
            }

            order = _orderRepository.AddOrder(order);

            carOrderDetails.OrderNo = order.Id.ToString();

            return(carOrderDetails);
        }
Esempio n. 6
0
 public ProductOption Handle(GetProductOptionQuery message)
 {
     return(_productOptionRepository.GetById(message.Id));
 }
Esempio n. 7
0
 /// <summary>
 /// Gets the product option by identifier.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <returns>ProductOption.</returns>
 public ProductOption GetProductOptionById(Guid id)
 {
     return(_productOptionRepository.GetById(id));
 }