/// <summary>
        /// Adds a Restriction to a Product's Measurement.
        /// </summary>
        /// <param name="addRestrictionToProductMeasurementMV">AddRestrictionToProductMeasurementModelView with the Product's and Measurement's persistence identifiers
        /// as well as the Restriction's data.</param>
        /// <returns>GetProductModelView with updated Product information.</returns>
        /// <exception cref="ResourceNotFoundException">Thrown when either the Product or the Measurement could not be found.</exception>
        public GetProductModelView addRestrictionToProductMeasurement(AddMeasurementRestrictionModelView addRestrictionToProductMeasurementMV)
        {
            ProductRepository productRepository = PersistenceContext.repositories().createProductRepository();

            Product product = productRepository.find(addRestrictionToProductMeasurementMV.productId);

            if (product == null)
            {
                throw new ResourceNotFoundException(string.Format(ERROR_UNABLE_TO_FIND_PRODUCT_BY_ID, addRestrictionToProductMeasurementMV.productId));
            }

            Measurement measurement = product.productMeasurements
                                      .Where(pm => pm.measurementId == addRestrictionToProductMeasurementMV.measurementId).Select(pm => pm.measurement).SingleOrDefault();

            if (measurement == null)
            {
                throw new ResourceNotFoundException(string.Format(ERROR_UNABLE_TO_FIND_MEASUREMENT_BY_ID, addRestrictionToProductMeasurementMV.measurementId));
            }

            Algorithm algorithm = new AlgorithmFactory().createAlgorithm(addRestrictionToProductMeasurementMV.restriction.algorithmId);

            if (addRestrictionToProductMeasurementMV.restriction.inputValues != null)
            {
                algorithm.setInputValues(InputValueModelViewService.toDictionary(addRestrictionToProductMeasurementMV.restriction.inputValues));
            }
            algorithm.ready();
            Restriction restriction = new Restriction(addRestrictionToProductMeasurementMV.restriction.description, algorithm);

            product.addMeasurementRestriction(measurement, restriction);

            product = productRepository.update(product);

            return(ProductModelViewService.fromEntity(product));
        }
        public ActionResult addRestrictionToProductMeasurement(long productId, long measurementId, [FromBody] AddRestrictionModelView restrictionMV)
        {
            if (restrictionMV == null)
            {
                return(BadRequest(new SimpleJSONMessageService(INVALID_RESTRICTION_DATA)));
            }

            AddMeasurementRestrictionModelView addRestrictionToProductMeasurementMV = new AddMeasurementRestrictionModelView();

            addRestrictionToProductMeasurementMV.productId     = productId;
            addRestrictionToProductMeasurementMV.measurementId = measurementId;
            addRestrictionToProductMeasurementMV.restriction   = restrictionMV;

            try {
                GetProductModelView productModelView = new core.application.ProductController().addRestrictionToProductMeasurement(addRestrictionToProductMeasurementMV);
                return(Created(Request.Path, productModelView));
            } catch (ResourceNotFoundException e) {
                return(NotFound(new SimpleJSONMessageService(e.Message)));
            } catch (ArgumentException e) {
                return(BadRequest(new SimpleJSONMessageService(e.Message)));
            } catch (Exception) {
                return(StatusCode(500, new SimpleJSONMessageService(UNEXPECTED_ERROR)));
            }
        }