public async Task <IActionResult> CreateProduct([FromBody] ProductCreationOptions product)
        {
            if (product == null)
            {
                ModelState.AddModelError(ErrorResponses.MissingBody, string.Empty);
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            product.ApplicableCharacteristicIDs ??= Enumerable.Empty <int>();

            var productModel = new Jibberwock.DataModels.Products.Product()
            {
                Name                        = product.Name,
                Description                 = product.Description,
                MoreInformationUrl          = product.MoreInformationUrl,
                Visible                     = product.Visible,
                ConfigurationControlName    = product.ConfigurationControlName,
                DefaultProductConfiguration = new Jibberwock.DataModels.Products.Configuration.RawProductConfiguration(product.DefaultProductConfiguration),
                ApplicableCharacteristics   = product.ApplicableCharacteristicIDs?.Select(i => new Jibberwock.DataModels.Products.ProductCharacteristic()
                {
                    Id = i
                }).ToArray()
            };

            var currentUser = await CurrentUserRetriever.GetCurrentUserAsync();

            var createProductCommand = new Jibberwock.Persistence.DataAccess.Commands.Products.CreateProduct(Logger, currentUser, HttpContext.TraceIdentifier, WebApiConfiguration.Authorization.DefaultServiceId, null, productModel);

            var creationSuccessful = await createProductCommand.Execute(SqlServerDataSource);

            return(Created(string.Empty, creationSuccessful.Result));
        }
        public async Task <IActionResult> UpdateProduct([FromRoute, ResourcePermissions(SecurableResourceType.Product, Permission.Change)] long id, [FromBody] ProductCreationOptions updatedProduct)
        {
            if (id == 0)
            {
                ModelState.AddModelError(ErrorResponses.InvalidId, string.Empty);
            }
            if (updatedProduct == null)
            {
                ModelState.AddModelError(ErrorResponses.MissingBody, string.Empty);
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var prodModel = new Product()
            {
                Id                          = id,
                Name                        = updatedProduct.Name,
                Description                 = updatedProduct.Description,
                MoreInformationUrl          = updatedProduct.MoreInformationUrl,
                Visible                     = updatedProduct.Visible,
                ConfigurationControlName    = updatedProduct.ConfigurationControlName,
                DefaultProductConfiguration = new Jibberwock.DataModels.Products.Configuration.RawProductConfiguration(updatedProduct.DefaultProductConfiguration),
                ApplicableCharacteristics   = updatedProduct.ApplicableCharacteristicIDs.Select(x => new ProductCharacteristic()
                {
                    Id = x
                })
            };
            var currentUser = await CurrentUserRetriever.GetCurrentUserAsync();

            var updateProductCommand = new Jibberwock.Persistence.DataAccess.Commands.Products.UpdateProduct(Logger, currentUser, HttpContext.TraceIdentifier, WebApiConfiguration.Authorization.DefaultServiceId, null, prodModel);

            var updateSuccessful = await updateProductCommand.Execute(SqlServerDataSource);

            if (updateSuccessful.Result != null)
            {
                return(Ok(updateSuccessful.Result));
            }
            else
            {
                return(NotFound());
            }
        }