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 DeleteButton_Click(object sender, EventArgs e)
 {
     if (Detach.Checked)
     {
         ProductKitComponent pkc = ProductKitComponentDataSource.Load(_Product.Id, _KitComponent.Id);
         int index = _Product.ProductKitComponents.IndexOf(pkc);
         if (index > -1)
         {
             _Product.ProductKitComponents.DeleteAt(index);
         }
     }
     else
     {
         _KitComponent.Delete();
     }
     Response.Redirect(string.Format("EditKit.aspx?CategoryId={0}&ProductId={1}", _CategoryId, _ProductId));
 }