protected void ComponentList_ItemCommand(object source, RepeaterCommandEventArgs e) { int kitComponentId = AlwaysConvert.ToInt(e.CommandArgument); KitComponent kitComponent = KitComponentDataSource.Load(kitComponentId); if (kitComponent != null) { switch (e.CommandName) { case "Branch": // locate the product relationship ProductKitComponent pkc = _Product.ProductKitComponents.FirstOrDefault(x => x.KitComponentId == kitComponent.Id); if (pkc != null) { // create a copy of the component KitComponent branchedComponent = kitComponent.Copy(true); branchedComponent.Save(); // update the product relationship _Product.ProductKitComponents.Add(new ProductKitComponent(_Product, branchedComponent, pkc.OrderBy)); _Product.ProductKitComponents.DeleteAt(_Product.ProductKitComponents.IndexOf(pkc)); _Product.Save(); } break; case "Delete": AbleContext.Current.Database.BeginTransaction(); ProductKitComponent matchingComponent = _Product.ProductKitComponents.FirstOrDefault(x => x.KitComponentId == kitComponentId); if (matchingComponent != null) { int index = _Product.ProductKitComponents.IndexOf(matchingComponent); if (index > -1) { _Product.ProductKitComponents.RemoveAt(index); _Product.Save(); } } kitComponent.Delete(); // DELETE THE KIT RECORD IF NO COMPONENTS REMAINING if (_Product.ProductKitComponents.Count == 0) { Kit kit = _Product.Kit; _Product.Kit = null; _Product.Save(); kit.Delete(); } AbleContext.Current.Database.CommitTransaction(); ComponentList.DataBind(); break; } } }
protected void BindComponentList() { List <KitComponent> components = new List <KitComponent>(); foreach (ProductKitComponent pkc in _Product.ProductKitComponents) { KitComponent kc = pkc.KitComponent; if (kc != null) { kc.RemoveInvalidKitProducts(); components.Add(kc); } } if (components.Count > 0) { if (_Kit == null) { // WE MUST HAVE KIT TO BIND COMPONENTS _Kit = new Kit(_Product, false); _Kit.Save(); } ComponentList.DataSource = components; ComponentList.DataBind(); SortComponents.Visible = (components.Count > 1); PriceRange.Text = string.Format("{0} - {1}", _Kit.MinPrice.LSCurrencyFormat("lc"), _Kit.MaxPrice.LSCurrencyFormat("lc")); DefaultPrice.Text = _Kit.DefaultPrice.LSCurrencyFormat("lc"); WeightRange.Text = string.Format("{0:F2} - {1:F2}", _Kit.MinWeight, _Kit.MaxWeight); DefaultWeight.Text = string.Format("{0:F2}", _Kit.DefaultWeight); ExistingKitPanel.Visible = true; NewKitPanel.Visible = false; } else { ExistingKitPanel.Visible = false; NewKitPanel.Visible = true; } }