protected void btnSaveAttTemplate_Click(object sender, EventArgs e) { Commerce.Common.Attribute att = new Commerce.Common.Attribute(); Attributes atts = new Attributes(); AttributeTemplate attributeTemplate = new AttributeTemplate(); attributeTemplate.AttributeName = txtAttributeNew.Text.Trim(); attributeTemplate.AttributeTypeID = int.Parse(ddlAttNewSelectionType.SelectedValue); ArrayList aList = GetSelections(); if (aList != null) { if (aList.Count > 0) { att.Selections = new System.Collections.Generic.List <AttributeSelection>(); for (int i = 0; i < aList.Count; i++) { att.Selections.Add((AttributeSelection)aList[i]); } } } atts.Add(att); attributeTemplate.SelectionList = Utility.ObjectToXML(typeof(Attributes), atts); attributeTemplate.Description = txtAttNewDesc.Text.Trim(); attributeTemplate.Save(Page.User.Identity.Name); lblTemplateSaved.Text = " Template Saved"; LoadAttributeTemplates(); }
protected void btnAddAttribute_Click(object sender, EventArgs e) { Commerce.Common.Attribute att = new Commerce.Common.Attribute(); att.Name = txtAttributeNew.Text.Trim(); att.Description = txtAttNewDesc.Text.Trim(); att.SelectionType = (AttributeType)int.Parse(ddlAttNewSelectionType.SelectedValue); //get the selections from the viewstate ArrayList aList = GetSelections(); att.Selections = new System.Collections.Generic.List <AttributeSelection>(); if (att.SelectionType != AttributeType.UserInput) { for (int i = 0; i < aList.Count; i++) { att.Selections.Add((AttributeSelection)aList[i]); } } else { AttributeSelection sel = new AttributeSelection(); sel.Value = ""; sel.PriceAdjustment = 0; att.Selections.Add(sel); } //a product can have one or more attribute selections //like "size" and "color" //store these into the viewstate as they are saved //and synch them with the product bits as well Commerce.Common.Attributes atts = null; if (ViewState["atts"] == null) { atts = new Attributes(); } else { atts = (Attributes)ViewState["atts"]; } atts.Add(att); //put it back the ViewState ViewState["atts"] = atts; //and set it to the product, which will serialize it down //to XML ProductController.UpdateProductAttributes(int.Parse(lblID.Text), atts); //bind up the grid BindAttList(atts); }