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 ActionResult Insert() { Buyer newBuyer = new Buyer(); saver.AddToContext(newBuyer); if (SaveBuyer(newBuyer)) { SetSuccessMessage("Buyer saved."); return RedirectToAction("Index"); } else return View("New", new EditData(newBuyer, _metaProductRepo.CurrentMetaProduct)); }
/// <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)); }
/// <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)); }
public MatchResult Match(Buyer buyer, IList<Product> products) { var previouslySent = productRepository.PreviouslySent(buyer.Id); var buyerMatches = new MatchResult(buyer, products.Where(product => buyer.IsMatch(product) && !previouslySent.Contains(product)).ToList()); return buyerMatches; }
public ActionResult New() { Buyer b = new Buyer(); return View("New", new EditData(b, _metaProductRepo.CurrentMetaProduct)); }
public UnsubscribeResult(Buyer buyer, bool success) { BuyerId = buyer.Id; BuyerName = buyer.FullName; Success = success; }
public EditData(Buyer b, MetaProduct mp) { Buyer = b; CurrentMetaProduct = mp; }
private void SetErrors(Buyer b) { Contract.Assert(b.HasErrors, "Set errors passed a valid entity."); SetModelErrors(b, "Save failed."); }
private bool SaveBuyer(Buyer b) { Request.ValidateInput(); var errorCollection = new List<ValidationFailure>(); try { UpdateModel(b, new[] { "FirstName", "LastName", "Email" }); } catch (HttpRequestValidationException) { errorCollection.Add(new ValidationFailure(String.Empty, "Request validation error.", String.Empty)); b.AddValidationFailure(errorCollection); SetErrors(b); return false; } errorCollection.AddRange(ValidateAttributeValues()); if (errorCollection.Count > 0) { b.AddValidationFailure(errorCollection); SetErrors(b); return false; } // buyer attributes are all valid foreach (MetaAttribute ma in _metaProductRepo.CurrentMetaProduct.MetaAttributes) { switch (ma.SetOrRangeEnum) { case MetaAttribute.MetaAttributeSetOrRange.SET: { _buyerService.UpsertPreference(b, _metaProductRepo.CurrentMetaProduct, ma, Request.Form[ma.PreferenceSetControlName]); break; } case MetaAttribute.MetaAttributeSetOrRange.RANGE: { if (Request.Form[ma.PreferenceLowerBoundHtmlControlName] != null && Request.Form[ma.PreferenceUpperBoundHtmlControlName] != null) _buyerService.UpsertPreference(b, _metaProductRepo.CurrentMetaProduct, ma, Request.Form[ma.PreferenceLowerBoundHtmlControlName], Request.Form[ma.PreferenceUpperBoundHtmlControlName]); break; } default: throw new Exception("Unknown preference SET or RANGE " + ma.SetOrRangeEnum.ToString()); } } if (!b.IsValid) { SetErrors(b); return false; } else { saver.SaveAll(); SetSuccessMessage("Buyer saved."); return true; } }
private void DeleteBuyer(Buyer toDelete) { int buyerId = toDelete.Id; string buyerName = toDelete.FullName; saver.MarkForDeletion(toDelete); saver.SaveAll(); TempData[SharedHelper.TempDataKeys.success.ToString()] = String.Format("Buyer {0}({1}) successfully deleted.", buyerName, buyerId); }
public static string BuyerRowClass(Buyer b) { return (b.IsUnsubscribed) ? "unsubscribed" : String.Empty; }
partial void DeleteBuyer(Buyer instance);
partial void UpdateBuyer(Buyer instance);
partial void InsertBuyer(Buyer instance);