コード例 #1
0
        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;
                }
            }
        }
コード例 #2
0
 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));
 }
コード例 #3
0
 protected void SaveButton_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(SortOrder.Value))
     {
         IList <ProductKitComponent> components = _Product.ProductKitComponents;
         string[] componentIds = SortOrder.Value.Split(",".ToCharArray());
         int      order        = 0;
         foreach (string sPartId in componentIds)
         {
             int componentId = AlwaysConvert.ToInt(sPartId);
             ProductKitComponent kitComponent = _Product.ProductKitComponents.FirstOrDefault(pkc => pkc.KitComponentId == componentId);
             if (kitComponent != null)
             {
                 kitComponent.OrderBy = (short)order;
                 order++;
             }
         }
         components.Save();
     }
     Response.Redirect("EditKit.aspx?CategoryId=" + _CategoryId.ToString() + "&ProductId=" + _ProductId.ToString());
 }