Пример #1
0
        public async Task <int> CloneProductAsync(int productId, string newSku, string newName)
        {
            var productInOneLevel = await GetFirstOrDefaultAsync(productId);

            if (productInOneLevel == null)
            {
                throw new Exception("Product not found!!!");
            }

            var newProduct = ProductFactory.CreateNewProductFromExistedProduct(productInOneLevel, newSku, newName, false);

            ProductFactory.AddFeatures(await GetFirstOrDefaultWithIncludesAsync(productId), ref newProduct);

            _context.Product.Add(newProduct);

            await _context.SaveChangesAsync();

            return(newProduct.Id);
        }