/// <summary> /// Creates a copy of this KitComponent object /// </summary> /// <param name="productId">Id of the product to attach the new object to</param> /// <returns>A copy of this KitComponent object</returns> public KitComponent Copy(int productId) { KitComponent copiedComponent = this.InternalCopy(); copiedComponent.ProductKitComponents.Add(new ProductKitComponent(productId, copiedComponent.KitComponentId)); copiedComponent.Save(); return(copiedComponent); }
private KitComponent InternalCopy() { //CREATE AN EXACT DUPLICATE OF THIS KIT COMPONENT KitComponent copiedComponent = KitComponentDataSource.Load(this.KitComponentId, false); //MAKE COPIES OF THE ASSOCIATED PRODUCTS foreach (KitProduct item in copiedComponent.KitProducts) { item.KitProductId = 0; } //RESET THE COMPONENTID copiedComponent.KitComponentId = 0; //SAVE THE NEW COMPONENT copiedComponent.Save(); return(copiedComponent); }
/// <summary> /// Creates a new KitComponent object based on this KitComponent object and attaches it as a component to the given product /// </summary> /// <param name="productId">Id of the product to which to attach the branched component</param> /// <returns>The newly created KitComponent</returns> public KitComponent Branch(int productId) { //REMOVE SPECIFIED PRODUCT FROM ORIGINAL COMPONENT short orderBy = -1; int index = this.ProductKitComponents.IndexOf(productId, this.KitComponentId); if (index > -1) { orderBy = this.ProductKitComponents[index].OrderBy; this.ProductKitComponents.DeleteAt(index); } //CREATE A COPY KitComponent branchedComponent = this.InternalCopy(); //ATTACH THE CURRENT PRODUCT ProductKitComponent pkc = new ProductKitComponent(productId, branchedComponent.KitComponentId); pkc.OrderBy = orderBy; branchedComponent.ProductKitComponents.Add(pkc); branchedComponent.Save(); //RETURN THE BRANCHED COMPONENT return(branchedComponent); }
public static SaveResult Insert(KitComponent kitComponent) { return(kitComponent.Save()); }
public static SaveResult Update(KitComponent kitComponent) { return(kitComponent.Save()); }
private void CopyChildren() { foreach (ProductAsset asset in Assets) { asset.ProductAssetId = 0; } foreach (ProductCustomField field in CustomFields) { field.ProductFieldId = 0; } foreach (ProductDigitalGood good in DigitalGoods) { good.ProductDigitalGoodId = 0; } foreach (ProductImage image in Images) { image.ProductImageId = 0; } foreach (ProductKitComponent comp in ProductKitComponents) { KitComponent kcomp = comp.KitComponent; kcomp.KitComponentId = 0; kcomp.Save(); comp.KitComponentId = comp.KitComponentId; } foreach (ProductTemplateField field in TemplateFields) { field.ProductTemplateFieldId = 0; } foreach (Special special in Specials) { List <int> groupIds = new List <int>(); foreach (SpecialGroup sg in special.SpecialGroups) { groupIds.Add(sg.GroupId); } special.SpecialId = 0; special.Save(); // ADD THE SPECIAL GROUPS special.SpecialGroups.Clear(); foreach (int groudId in groupIds) { special.SpecialGroups.Add(new SpecialGroup(special.SpecialId, groudId)); } } List <int> oldChoiceIds = new List <int>(); List <int> newChoiceIds = new List <int>(); int oldChoiceId, newChoiceId; foreach (ProductOption option in ProductOptions) { Option opt = option.Option; foreach (OptionChoice choice in opt.Choices) { oldChoiceId = choice.OptionChoiceId; choice.OptionChoiceId = 0; oldChoiceIds.Add(oldChoiceId); } opt.OptionId = 0; opt.Save(); option.OptionId = opt.OptionId; foreach (OptionChoice choice in opt.Choices) { newChoiceId = choice.OptionChoiceId; newChoiceIds.Add(newChoiceId); } } Dictionary <int, int> optChoiceIdMap = new Dictionary <int, int>(); if (oldChoiceIds.Count == newChoiceIds.Count) { for (int i = 0; i < oldChoiceIds.Count; i++) { optChoiceIdMap.Add(oldChoiceIds[i], newChoiceIds[i]); } } foreach (ProductVariant pv in Variants) { pv.ProductVariantId = 0; pv.Option1 = GetNewChoiceId(pv.Option1, optChoiceIdMap); pv.Option2 = GetNewChoiceId(pv.Option2, optChoiceIdMap); pv.Option3 = GetNewChoiceId(pv.Option3, optChoiceIdMap); pv.Option4 = GetNewChoiceId(pv.Option4, optChoiceIdMap); pv.Option5 = GetNewChoiceId(pv.Option5, optChoiceIdMap); pv.Option6 = GetNewChoiceId(pv.Option6, optChoiceIdMap); pv.Option7 = GetNewChoiceId(pv.Option7, optChoiceIdMap); pv.Option8 = GetNewChoiceId(pv.Option8, optChoiceIdMap); } }