protected override void OnInit(EventArgs e) { base.OnInit(e); long propertyId = -1; if (Request.QueryString["id"] != null) { propertyId = long.Parse(Request.QueryString["id"]); } localProperty = MTApp.CatalogServices.ProductProperties.Find(propertyId); }
protected void btnNew_Click(System.Object sender, System.Web.UI.ImageClickEventArgs e) { msg.ClearMessage(); ProductProperty p = new ProductProperty(); p.DisplayName = "New Property"; p.TypeCode = (ProductPropertyType)int.Parse(lstProductType.SelectedValue); if (MTApp.CatalogServices.ProductProperties.Create(p) == true) { FillList(); } else { msg.ShowError("Error while attempting to create new property."); } }
private void LoadProperty(ProductProperty prop) { if (prop != null) { this.PropertyNameField.Text = prop.PropertyName; this.DisplayNameField.Text = prop.DisplayName; this.chkDisplayOnSite.Checked = prop.DisplayOnSite; this.chkDisplayToDropShipper.Checked = prop.DisplayToDropShipper; this.DefaultValueField.Text = prop.DefaultValue; foreach (System.Web.UI.WebControls.ListItem li in lstCultureCode.Items) { if (li.Value == prop.CultureCode) { lstCultureCode.ClearSelection(); li.Selected = true; } } this.DefaultValueField.TextMode = TextBoxMode.MultiLine; //Me.DefaultDate.SetYearRange(Date.Now.Year - 50, Date.Now.Year + 50) if (prop.TypeCode == ProductPropertyType.DateField) { System.DateTime d = new System.DateTime(); d = System.DateTime.Now; try { if (prop.DefaultValue.Trim().Length > 0) { d = System.DateTime.Parse(prop.DefaultValue); } } catch (Exception ex) { MerchantTribe.Commerce.EventLog.LogEvent(ex); } this.DefaultDate.SelectedDate = d; } DisplayProperControls(prop); } else { msg.ShowError("Unable to load Product Property ID " + (string)ViewState["ID"]); } }
// Create or Update public override string PostAction(string parameters, System.Collections.Specialized.NameValueCollection querystring, string postdata) { string data = string.Empty; string ids = FirstParameter(parameters); long id = 0; long.TryParse(ids, out id); string isValueSetRequest = GetParameterByIndex(1, parameters); if (isValueSetRequest.Trim().ToLowerInvariant() == "valuesforproduct") { // Set Property value Request ApiResponse<bool> response = new ApiResponse<bool>(); string productBvin = GetParameterByIndex(2, parameters); string propertyValue = postdata; response.Content = MTApp.CatalogServices.ProductPropertyValues.SetPropertyValue(productBvin, id, propertyValue); data = MerchantTribe.Web.Json.ObjectToJson(response); } else { // Regular Create or Update Request ApiResponse<ProductPropertyDTO> response = new ApiResponse<ProductPropertyDTO>(); ProductPropertyDTO postedItem = null; try { postedItem = MerchantTribe.Web.Json.ObjectFromJson<ProductPropertyDTO>(postdata); } catch (Exception ex) { response.Errors.Add(new ApiError("EXCEPTION", ex.Message)); return MerchantTribe.Web.Json.ObjectToJson(response); } ProductProperty item = new ProductProperty(); item.FromDto(postedItem); // Check for existing and create base property ProductProperty existing = MTApp.CatalogServices.ProductProperties.FindByName(item.DisplayName); if (existing == null) { // Create MTApp.CatalogServices.ProductProperties.Create(item); id = item.Id; //// Merge Properties //foreach (ProductPropertyChoice ppc in item.Choices) //{ // ppc.PropertyId = item.Id; // ProductPropertyChoice.Insert(ppc); //} } else { // Update MTApp.CatalogServices.ProductProperties.Update(item); id = existing.Id; //// Merge Properties //if (item.Choices.Count > 0) //{ // List<ProductPropertyChoice> existingChoices = ProductPropertyChoice.FindByPropertyID(existing.Id); // foreach (ProductPropertyChoice newChoice in item.Choices) // { // var existCount = existingChoices.Where(y => y.Id == newChoice.Id).Count(); // if (existCount < 1) // { // newChoice.PropertyId = existing.Id; // ProductPropertyChoice.Insert(newChoice); // } // else // { // ProductPropertyChoice.Update(newChoice); // } // } //} } ProductProperty resultItem = MTApp.CatalogServices.ProductProperties.Find(id); if (resultItem != null) response.Content = resultItem.ToDto(); data = MerchantTribe.Web.Json.ObjectToJson(response); } return data; }
private void RenderSingleProperty(ProductProperty p, StringBuilder sb) { sb.Append("<div class=\"dragitem\" id=\"" + p.Id.ToString() + "\">"); sb.Append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">"); sb.Append("<tr>"); sb.Append("<td width=\"25%\">" + p.FriendlyTypeName + "</td>"); sb.Append("<td width=\"50%\">" + p.PropertyName + "</td>"); sb.Append("<td><a href=\"ProductTypes_RemoveProperty.aspx\" title=\"Remove Product Property\" id=\"rem" + p.Id.ToString() + "\" class=\"trash\"><img src=\"../../images/system/trashcan.png\" alt=\"Remove Property\" border=\"0\" /></a></td>"); sb.Append("<td class=\"handle\" align=\"right\"><img src=\"../../images/system/draghandle.png\" alt=\"sort\" border=\"0\" /></td>"); sb.Append("</tr>"); sb.Append("</table>"); sb.Append("</div>"); }
public string FormatProductPropertyChoiceValue(ProductProperty prop, string value) { if (prop == null) return value; switch (prop.TypeCode) { case Catalog.ProductPropertyType.MultipleChoiceField: foreach (Catalog.ProductPropertyChoice choice in prop.Choices) { long temp = -1; long.TryParse(value, out temp); if (choice.Id == temp) { return choice.ChoiceName; } } return ""; case Catalog.ProductPropertyType.CurrencyField: System.Globalization.CultureInfo info = new System.Globalization.CultureInfo(prop.CultureCode); decimal temp2 = -1; decimal.TryParse(value, out temp2); return string.Format(info.NumberFormat, "{0:c}", temp2); default: return value; } }
private void RenderSelection(StringBuilder sb, int index, long selectedValue, string key, CategoryFacet facet, ProductProperty property, List<CategoryFacet> allFacets, CategoryPageViewModel model, List<BreadCrumbItem> extraCrumbs) { string selectedName = string.Empty; var sn = (from c in property.Choices where c.Id == selectedValue select c.ChoiceName).SingleOrDefault(); if (sn != null) { selectedName = sn; extraCrumbs.Add(new BreadCrumbItem() { Name = sn }); ViewBag.MetaDescription += " | " + sn; ViewBag.Title += " | " + sn; } sb.Append("<h6 class=\"filter\">" + property.DisplayName + "</h6> "); string baseUrl = model.LocalCategory.RewriteUrl + "?node=" + CategoryFacetKeyHelper.ClearSelfAndChildrenFromKey(key, allFacets, facet.Id); sb.Append("<ul class=\"filterselected\"><li>"); sb.Append(" <a href=\"" + baseUrl + "\">"); sb.Append(selectedName); sb.Append(" [clear]</a></li></ul>"); }
private void RenderNonSelection(StringBuilder sb, int index, long selectedValue, string key, CategoryFacet facet, ProductProperty property, List<ProductFacetCount> counts, CategoryPageViewModel model) { sb.Append("<h6 class=\"filter\">" + property.DisplayName + "</h6>"); sb.Append("<ul class=\"filterselections\">"); foreach (ProductPropertyChoice c in property.Choices) { string newKey = CategoryFacetKeyHelper.ReplaceKeyValue(key, index, c.Id); string baseUrl = model.LocalCategory.RewriteUrl + "?node=" + newKey; string sqlKey = CategoryFacetKeyHelper.ParseKeyToSqlList(newKey); ProductFacetCount fc = new ProductFacetCount(); foreach (ProductFacetCount f in counts) { if (f.Key == sqlKey) { fc = f; break; } } if (fc.ProductCount > 0) { sb.Append("<li><a href=\"" + baseUrl + "\">"); sb.Append(c.ChoiceName); sb.Append(" (" + fc.ProductCount.ToString() + ")"); sb.Append("</a></li>"); } } sb.Append("</ul>"); }
protected void btnNewChoice_Click(System.Object sender, System.Web.UI.ImageClickEventArgs e) { msg.ClearMessage(); ProductProperty prop = new ProductProperty(); prop = MTApp.CatalogServices.ProductProperties.Find((long)ViewState["ID"]); if (prop != null) { ProductPropertyChoice ppc = new ProductPropertyChoice(); ppc.ChoiceName = this.NewChoiceField.Text.Trim(); ppc.PropertyId = (long)ViewState["ID"]; prop.Choices.Add(ppc); if (MTApp.CatalogServices.ProductProperties.Update(prop)) { PopulateMultipleChoice(prop); } else { msg.ShowError("Couldn't add choice!"); } this.NewChoiceField.Text = string.Empty; } }
protected void btnDelete_Click(System.Object sender, System.Web.UI.ImageClickEventArgs e) { if (this.lstDefaultValue.Items.Count > 0) { ProductProperty prop = new ProductProperty(); prop = MTApp.CatalogServices.ProductProperties.Find((long)ViewState["ID"]); if (prop != null) { long choiceId = long.Parse(lstDefaultValue.SelectedValue); ProductPropertyChoice c = prop.Choices.Where(y => y.Id == choiceId).FirstOrDefault(); if (c != null) { prop.Choices.Remove(c); MTApp.CatalogServices.ProductProperties.Update(prop); localProperty = prop; } PopulateMultipleChoice(prop); } } }
protected void btnSave_Click(System.Object sender, System.Web.UI.ImageClickEventArgs e) { msg.ClearMessage(); ProductProperty prop = new ProductProperty(); prop = MTApp.CatalogServices.ProductProperties.Find((long)ViewState["ID"]); if (prop != null) { prop.PropertyName = PropertyNameField.Text; prop.DisplayName = DisplayNameField.Text; prop.DisplayOnSite = chkDisplayOnSite.Checked; prop.DisplayToDropShipper = chkDisplayToDropShipper.Checked; switch (prop.TypeCode) { case ProductPropertyType.CurrencyField: prop.CultureCode = lstCultureCode.SelectedValue; prop.DefaultValue = DefaultValueField.Text.Trim(); break; case ProductPropertyType.MultipleChoiceField: prop.DefaultValue = lstDefaultValue.SelectedValue; break; case ProductPropertyType.DateField: prop.DefaultValue = string.Format("{0:d}", DefaultDate.SelectedDate); break; case ProductPropertyType.TextField: prop.DefaultValue = DefaultValueField.Text.Trim(); break; } if (MTApp.CatalogServices.ProductProperties.Update(prop) == true) { prop = null; Response.Redirect("~/BVAdmin/Catalog/ProductTypeProperties.aspx"); } else { prop = null; msg.ShowError("Error: Couldn't Save Property!"); } } else { msg.ShowError("Couldn't Load Property to Update!"); } }
private void PopulateMultipleChoice(ProductProperty p) { this.lstDefaultValue.DataSource = p.Choices; this.lstDefaultValue.DataTextField = "ChoiceName"; this.lstDefaultValue.DataValueField = "id"; this.lstDefaultValue.DataBind(); foreach (System.Web.UI.WebControls.ListItem li in lstDefaultValue.Items) { if (li.Value == DefaultValueField.Text.Trim()) { lstDefaultValue.ClearSelection(); li.Selected = true; } } }
private void DisplayProperControls(ProductProperty prop) { ProductPropertyType typeCode = prop.TypeCode; this.pnlChoiceControls.Visible = false; pnlCultureCode.Visible = false; this.DefaultDate.Visible = false; switch (typeCode) { case ProductPropertyType.CurrencyField: pnlCultureCode.Visible = true; DefaultValueField.Visible = true; lstDefaultValue.Visible = false; ChoiceNote.InnerText = "Default Value"; break; case ProductPropertyType.DateField: DefaultValueField.Visible = false; lstDefaultValue.Visible = false; this.DefaultDate.Visible = true; ChoiceNote.InnerText = "Default Value"; break; case ProductPropertyType.MultipleChoiceField: lstDefaultValue.Visible = true; DefaultValueField.Visible = false; PopulateMultipleChoice(prop); ChoiceNote.InnerText = "To select a default simply select the item in the list before you hit save."; this.pnlChoiceControls.Visible = true; break; case ProductPropertyType.TextField: DefaultValueField.Visible = true; lstDefaultValue.Visible = false; ChoiceNote.InnerText = "Default Value"; break; } }