protected void lnkSave_OnCommand(object sender, CommandEventArgs e) { //check if the product to be added will contain sub products RadioButtonList rbtnContainSubProduct = (fviewProduct.FindControl("rbtnContainSubProduct") as RadioButtonList); if (rbtnContainSubProduct.SelectedValue == "yes") { //get the data from the form Product mainProduct = new Product(); GetDetailsFromFormView(mainProduct); //save the main product to be added mainProduct.ProductID = ProductManager.Save(mainProduct); //Gets the selected products from the sub product gridview List <int> subProductIDList = GetSelectedSubProductsFromGridview(); //Insert records in the Assembly table using the Main product Id and sub product ID foreach (int subProductID in subProductIDList) { ProductPartReplacement prodAssembly = new ProductPartReplacement(); prodAssembly.ProductID = mainProduct.ProductID; prodAssembly.SubProductID = subProductID; prodAssembly.CreatedBy = User.Identity.Name.ToString(); //save the records ProductPartReplacementManager.Save(prodAssembly); } } else if (rbtnContainSubProduct.SelectedValue == "no") { //get the data from the form Product product = new Product(); GetDetailsFromFormView(product); //save the main product to be added product.ProductID = ProductManager.Save(product); } //Bring the form to its initial state ResetFieldsAndGridview(); }
protected void lnkSaveSubProductEdit_OnCommand(object sender, CommandEventArgs e) { //Gets the selected products from the sub product gridview List <int> subProductIDList = GetSelectedSubProductsFromGridview(); //Insert records in the Assembly table using the Main product Id and sub product ID foreach (int subProductID in subProductIDList) { ProductPartReplacement prodAssembly = new ProductPartReplacement(); prodAssembly.ProductID = product.ProductID; prodAssembly.SubProductID = subProductID; prodAssembly.CreatedBy = User.Identity.Name.ToString(); //save the records ProductPartReplacementManager.Save(prodAssembly); } ProductList p = new ProductList(); p.Add(product); PopulateDetailsview(p); }