public void AddExtraKey([FromBody] ExtraKeyViewModel model)
        {
            ExtraKeyValidator validator = new ExtraKeyValidator(_productManager);
            var results = validator.Validate(model);

            if (!results.IsValid)
            {
                TempData[TextConstants.TempDataKeyErrorText] = ValidatorHelper.GetErrorString(results.Errors);
                return;
            }

            Product product = _productManager.GetProductCopyByKey(model.ProductKey);

            model.ExtraProductKey = KeyGenerator.GenerateExtraProductKey(
                product.Name, model.ExtraKeyName);

            var extraProduct = new ExtraProductKey(model.ExtraKeyName, model.ExtraProductKey);

            if (product.ExtraKeys == null || product.ExtraKeys.Count == 0)
            {
                product.ExtraKeys = new List <ExtraProductKey> {
                    extraProduct
                }
            }
            ;
            else
            {
                product.ExtraKeys.Add(extraProduct);
            }

            _productManager.UpdateProduct(product);
        }
        public void ExtraKeyMustBeAdded()
        {
            //Arrange
            var product  = _databaseFixture.GetFirstTestProduct();
            var key      = KeyGenerator.GenerateExtraProductKey(product.Name, _databaseFixture.ExtraKeyName);
            var extraKey = new ExtraProductKey {
                Key = key, Name = _databaseFixture.ExtraKeyName
            };

            product.ExtraKeys = new List <ExtraProductKey> {
                extraKey
            };

            //Act
            _databaseFixture.DatabaseAdapter.UpdateProduct(product);

            //Assert
            var gotProduct = _databaseFixture.DatabaseAdapter.GetProduct(product.Name);

            Assert.NotEmpty(gotProduct.ExtraKeys);
            var keyFromDB = gotProduct.ExtraKeys.First();

            Assert.Equal(extraKey.Name, keyFromDB.Name);
            Assert.Equal(extraKey.Key, keyFromDB.Key);
        }
        internal static void AddExtraKey(this Product product, string extraKeyName)
        {
            var extraKey = new ExtraProductKey
            {
                Name = extraKeyName,
                Key  = KeyGenerator.GenerateExtraProductKey(product.Name, extraKeyName)
            };

            product.ExtraKeys.Add(extraKey);
        }