public int InsertProduct(ProductsInsert productsInsert) { int ProductIDFromInsert = 0; using (SqlConnection connection = new SqlConnection(connectionString)) { using (SqlCommand command = new SqlCommand("ProcedureInsertProductsV3", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@ProductSKUID", productsInsert.ProductSKUID); command.Parameters.AddWithValue("@ProductNameID", productsInsert.ProductNameID); command.Parameters.AddWithValue("@ProductBrandID", productsInsert.ProductBrandID); command.Parameters.AddWithValue("@ProductPriceID", productsInsert.ProductPriceID); command.Parameters.AddWithValue("@ProductVariableCostID", productsInsert.ProductVariableCostID); command.Parameters.AddWithValue("@ProductStartFactorID", productsInsert.ProductStartFactorID); command.Parameters.AddWithValue("@ProductGrowthFactorID", productsInsert.ProductGrowthFactorID); command.Parameters.AddWithValue("@ProductID_Output", ProductIDFromInsert).Direction = ParameterDirection.Output; connection.Open(); command.ExecuteNonQuery(); ProductIDFromInsert = Convert.ToInt32(command.Parameters["@ProductID_Output"].Value); } return(ProductIDFromInsert); } }
public void InsertProductMaterial(int productID, ProductsInsertComplex productsInsertComplex) { ProductsInsert productsInsert = new ProductsInsert(); foreach (ProductsInsertComplex.ProductsInsertMaterial productsInsertMaterial in productsInsertComplex.productsInsertMaterials) { InsertMaterial(productID, productsInsertMaterial.MaterialName); Console.WriteLine(productID + productsInsertMaterial.MaterialName); } }
/* * public ProductsInsert InsertProduct(ProductsInsertComplex productsInsertComplex) * { * ProductsInsert productsInsert = new ProductsInsert(); * * productsInsert = InsertProductToID(productsInsertComplex); * * * return productsInsert; * }*/ public ProductsInsert InsertProduct(ProductsInsertComplex productsInsertComplex) { SKUID = InsertSKU(productsInsertComplex.ProductSKU); NameID = InsertName(productsInsertComplex.ProductName); BrandID = InsertBrand(productsInsertComplex.ProductBrand); PriceID = InsertPrice(productsInsertComplex.ProductPrice); VariableCostID = InsertVariableCost(productsInsertComplex.ProductVariableCost); StartFactorID = InsertStartFactor(productsInsertComplex.ProductStartFactor); GrowthFactorID = InsertGrowthFactor(productsInsertComplex.ProductGrowthFactor); ProductsInsert productsInsert = new ProductsInsert(SKUID, NameID, BrandID, PriceID, VariableCostID, StartFactorID, GrowthFactorID); return(productsInsert); }
public IActionResult Post([FromBody] ProductsInsertComplex productsInsertComplex) { ProductsInsert productsInsert = new ProductsInsert(0, 0, 0, 0, 0, 0, 0); PriceOptimize priceOptimize = new PriceOptimize(); productsInsertComplex.ProductPrice = priceOptimize.OptimizePrice(productsInsertComplex.ProductVariableCost, productsInsertComplex.ProductStartFactor, productsInsertComplex.ProductGrowthFactor); productsInsert = new ProductsInsertDataLayer(_configuration).InsertProduct(productsInsertComplex); int ProductID = new ProductsDataLayer(_configuration).InsertProduct(productsInsert); new ProductsInsertDataLayer(_configuration).InsertProductMaterial(ProductID, productsInsertComplex); new ProductsInsertDataLayer(_configuration).InsertProductQuantity(ProductID, productsInsertComplex); return(Ok()); }