private void addFeatureToEveryProductWithMenuPath2(MenuPath2 menuPath2, MenuFeature menuFeature) { //Now add the feature to every product that has menu1 as its path. //first find all the menuMains that contain MenuPath1 if (menuPath2.MenuPathMains.IsNullOrEmpty()) { return; } List <MenuPathMain> menuPathMainList = menuPath2.MenuPathMains.ToList(); //Now get all the products that have theseMenuPaths as their path. HashSet <Product> productHashList = new HashSet <Product>(); foreach (var menuPathMain in menuPathMainList) { if (!menuPathMain.Products_Fixed.IsNullOrEmpty()) { List <Product> menuPathMainProductList = menuPathMain.Products_Fixed.ToList(); foreach (var prod in menuPathMainProductList) { productHashList.Add(prod); } } } if (productHashList.IsNullOrEmpty()) { return; } foreach (var prod2 in productHashList) { ProductFeature pf = new ProductFeature(); pf.ProductId = prod2.Id; pf.Product = prod2; pf.MenuFeatureId = menuFeature.Id; pf.MenuFeature = menuFeature; pf.Name = menuFeature.Name; ProductFeatureBiz.CreateAndSave(pf); } SaveChanges(); }
public void CreateNewFeature(CreateNewFeatureModel model) { model.SelfCheck(); ProductFeature productFeature = ProductFeatureBiz.FindByName(model.FeatureName); if (productFeature.IsNull()) { productFeature = ProductFeatureBiz.Factory() as ProductFeature; productFeature.IsNullThrowException("productFeature"); productFeature.Name = model.FeatureName; ProductFeatureBiz.CreateAndSave(productFeature); } //create the new feature. Product product = Find(model.ParentId); product.IsNullThrowException("product"); //taking a short cut. ProductFeatureModel productFeatureModel = new ProductFeatureModel(model.ParentId, "", productFeature.Id, model.ReturnUrl, model.Description); AddFeature(productFeatureModel); }