/// <summary>Generate a control for a range preference.</summary> private static string RangePreferenceControl(HtmlHelper helper, MetaAttribute ma, Preference preference) { string lowerBoundControl; string upperBoundControl; string currentLowerBound = null; string currentUpperBound = null; if (preference != null) { currentLowerBound = (preference.Range.LowerBound != null) ? preference.Range.LowerBound.Formatted : String.Empty; currentUpperBound = (preference.Range.UpperBound != null) ? preference.Range.UpperBound.Formatted : String.Empty; } if (ma.HasChoices) { SelectList lowerBoundListData = (preference != null) ? new SelectList(SelectHelper.DropDownRecordsFromValueSet(ma.ChoicesCollection), "Value", "Text", currentLowerBound) : new SelectList(SelectHelper.DropDownRecordsFromValueSet(ma.ChoicesCollection), "Value", "Text"); SelectList upperBoundListData = (preference != null) ? new SelectList(SelectHelper.DropDownRecordsFromValueSet(ma.ChoicesCollection), "Value", "Text", currentUpperBound) : new SelectList(SelectHelper.DropDownRecordsFromValueSet(ma.ChoicesCollection), "Value", "Text"); lowerBoundControl = helper.DropDownList(ma.PreferenceLowerBoundHtmlControlName, lowerBoundListData, OPTION_LABEL); upperBoundControl = helper.DropDownList(ma.PreferenceUpperBoundHtmlControlName, upperBoundListData, OPTION_LABEL); } else { lowerBoundControl = helper.TextBox(ma.PreferenceLowerBoundHtmlControlName, currentLowerBound, new {length=10}); upperBoundControl = helper.TextBox(ma.PreferenceUpperBoundHtmlControlName, currentUpperBound, new {length=10}); } return String.Format( "From {2}{0} to {2}{1}", lowerBoundControl, upperBoundControl, (ma.DataTypeEnum == MetaAttribute.MetaAttributeDataType.CURRENCY) ? "$" : String.Empty); }
public void UpsertAttribute_InsertSecond() { Mock<IProductRepository> productRepo = new Mock<IProductRepository>(); Mock<IImageResizer> imageResizer = new Mock<IImageResizer>(); ProductService service = new ProductService(productRepo.Object, imageResizer.Object, ServiceBuilder.Saver.Object); Product oneAtt = new Product(); MetaAttribute cost = new MetaAttribute(); cost.Id = 3; cost.DataTypeEnum = MetaAttribute.MetaAttributeDataType.CURRENCY; MetaAttribute height = new MetaAttribute(); height.Id = 6; height.DataTypeEnum = MetaAttribute.MetaAttributeDataType.INTEGER; ProductAttribute costAtt = new ProductAttribute(); costAtt.Id = 2; costAtt.MetaAttribute = cost; oneAtt.ProductAttributes.Add(costAtt); ProductAttribute heightAtt = new ProductAttribute(); heightAtt.Id = 8; heightAtt.MetaAttribute = height; productRepo.Expect(repo => repo.CreateProductAttribute(height)).Returns(heightAtt); service.UpsertAttribute(oneAtt, height, "69"); Assert.AreEqual(2, oneAtt.ProductAttributes.Count); }
/// <summary>Generate a control for a set preference.</summary> private static string SetPreferenceControl(HtmlHelper helper, MetaAttribute ma, Preference preference) { string result; if (ma.HasChoices) { if (preference != null) { MultiSelectList listData = new MultiSelectList(SelectHelper.DropDownRecordsFromValueSet(ma.ChoicesCollection), "Value", "Text", SelectHelper.ValuesFromValueSet(preference.Set)); result = helper.ListBox(ma.PreferenceSetControlName, listData); } else { MultiSelectList listData = new MultiSelectList(SelectHelper.DropDownRecordsFromValueSet(ma.ChoicesCollection), "Value", "Text"); result = helper.ListBox(ma.PreferenceSetControlName, listData); } } else { if (preference != null) { result = helper.TextBox(ma.PreferenceSetControlName, preference.RawValues); } else { result = helper.TextBox(ma.PreferenceSetControlName); } } return result; }
/// <summary>Generate a control for displaying an attribute.</summary> /// <param name="helper"></param><param name="ma"></param><param name="attribute"></param> /// <returns></returns> public static string AttributeControl(HtmlHelper helper, MetaAttribute ma, ProductAttribute attribute) { string result = (ma.DataTypeEnum == MetaAttribute.MetaAttributeDataType.CURRENCY) ? "$" : " "; return (ma.HasChoices) ? result + SelectableAttribute(helper, ma, attribute) : result + NonSelectableAttribute(helper, ma, attribute); }
private static string SelectableAttribute(HtmlHelper helper, MetaAttribute ma, ProductAttribute attribute) { SelectList listData = (attribute != null) ? new SelectList(SelectHelper.DropDownRecordsFromValueSet(ma.ChoicesCollection), "Value", "Text", (object)attribute.RawValue) : new SelectList(SelectHelper.DropDownRecordsFromValueSet(ma.ChoicesCollection), "Value", "Text"); return helper.DropDownList(ma.ProductAttributeHtmlControlName, listData, OPTION_LABEL); }
/// <summary>Generate a control for displaying a preference.</summary> /// <param name="helper"></param><param name="ma"></param><param name="preference"></param> /// <returns></returns> public static string PreferenceControl(HtmlHelper helper, MetaAttribute ma, Preference preference) { switch (ma.SetOrRangeEnum) { case MetaAttribute.MetaAttributeSetOrRange.SET: return SetPreferenceControl(helper, ma, preference); case MetaAttribute.MetaAttributeSetOrRange.RANGE: return RangePreferenceControl(helper, ma, preference); default: throw new Exception("Unknown Set or Range " + ma.SetOrRangeEnum.ToString()); } }
public IEnumerable<Product> FindProductsByFilter(MetaAttribute metaAttribute, string productAttributeRawValue1, IEnumerable<Product> products) { var templateBuyer = new Buyer(); var preference = new Preference(); preference.MetaAttribute = metaAttribute; preference.RawValues = productAttributeRawValue1; templateBuyer.Preferences.Add(preference); return products.Where(product => templateBuyer.IsMatch(product)); }
public void UpsertAttribute_Clear() { ProductService service = SetupProductService(); Product oneAtt = new Product(); MetaAttribute cost = new MetaAttribute(); cost.Id = 3; cost.DataTypeEnum = MetaAttribute.MetaAttributeDataType.CURRENCY; ProductAttribute costAtt = new ProductAttribute(); costAtt.Id = 2; costAtt.MetaAttribute = cost; oneAtt.ProductAttributes.Add(costAtt); service.UpsertAttribute(oneAtt, cost, ""); Assert.AreEqual(1, oneAtt.ProductAttributes.Count); }
/// <summary>Add/update a preference set on Buyer b.</summary> /// <param name="b"></param><param name="metaProduct"></param><param name="ma"></param><param name="rawValues"></param> public void UpsertPreference(Buyer b, MetaProduct metaProduct, MetaAttribute ma, string rawValues) { Preference pref = null; if (b.HasPreferenceFor(ma.Id)) { pref = b.GetPreference(ma.Id); if (String.IsNullOrEmpty(rawValues)) { saver.MarkForDeletion(pref); return; } } else { if (String.IsNullOrEmpty(rawValues)) return; pref = _buyerRepo.CreatePreference(b, ma); } pref.SetSet(new ValueSet(rawValues, ma.DataTypeEnum)); }
/// <summary>Add/update a preference range on Buyer b.</summary> public void UpsertPreference(Buyer b, MetaProduct metaProduct, MetaAttribute ma, string formattedLowerBound, string formattedUpperBound) { Preference pref = null; if (b.HasPreferenceFor(ma.Id)) { pref = b.GetPreference(ma.Id); if (IsEmptyRange(formattedLowerBound, formattedUpperBound)) { saver.MarkForDeletion(pref); return; } } else { if (IsEmptyRange(formattedLowerBound, formattedUpperBound)) return; pref = _buyerRepo.CreatePreference(b, ma); } pref.SetRange(new ValueRange(formattedLowerBound, formattedUpperBound, ma.DataTypeEnum, FormattedOrRaw.FORMATTED)); }
public void UpsertAttribute_Insert() { Mock<IProductRepository> productRepo = new Mock<IProductRepository>(); ProductService service = SetupProductService(); Product noAtts = new Product(); MetaAttribute metaAttribute = new MetaAttribute(); metaAttribute.Id = 5; metaAttribute.DataTypeEnum = MetaAttribute.MetaAttributeDataType.STRING; service.UpsertAttribute(noAtts, metaAttribute, ""); Assert.IsTrue(noAtts.ProductAttributes.Count == 0); ProductAttribute catAtt = new ProductAttribute(); catAtt.Id = 1; catAtt.MetaAttribute = metaAttribute; catAtt.Product = noAtts; productRepo.Expect(repo => repo.CreateProductAttribute(metaAttribute)).Returns(catAtt); service.UpsertAttribute(noAtts, metaAttribute, "cat"); Assert.AreEqual(1, noAtts.ProductAttributes.Count); }
partial void UpdateMetaAttribute(MetaAttribute instance);
private static string NonSelectableAttribute(HtmlHelper helper, MetaAttribute ma, ProductAttribute attribute) { return (attribute != null) ? helper.TextBox(ma.ProductAttributeHtmlControlName, attribute.ControlFormattedValue) : helper.TextBox(ma.ProductAttributeHtmlControlName); }
partial void DeleteMetaAttribute(MetaAttribute instance);
public MetaAttributeBuilder WithSetOrRange(MetaAttribute.MetaAttributeSetOrRange setOrRange) { _defaultSetOrRange = setOrRange; return this; }
partial void InsertMetaAttribute(MetaAttribute instance);
public ProductAttributeBuilder WithMetaAttribute(MetaAttribute attribute) { defaultMetaAttribute = attribute; return this; }
public PreferenceBuilder WithMetaAttribute(MetaAttribute attribute) { defaultMetaAttribute = attribute; return this; }
public MetaAttributeBuilder WithDataType(MetaAttribute.MetaAttributeDataType dataType) { _defaultDataType = dataType; return this; }
/// <summary>See IProductService.</summary> /// <param name="metaAttribute"></param><param name="value"></param> public void UpsertAttribute(Product p, MetaAttribute metaAttribute, string value) { if (p.HasAttributeFor(metaAttribute.Id)) { // update ProductAttribute att = p.GetAttribute(metaAttribute.Id); if (value.Equals(String.Empty)) { saver.MarkForDeletion(att); } else att.SetFormattedValue(value); } else { // insert if (value.Equals(String.Empty)) return; // no value entered. ProductAttribute att = _productRepository.CreateProductAttribute(metaAttribute); p.ProductAttributes.Add(att); att.SetFormattedValue(value); } }
private void detach_MetaAttributes(MetaAttribute entity) { this.SendPropertyChanging(); entity.MetaProduct = null; }