Esempio n. 1
0
 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));
 }
Esempio n. 2
0
 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));
 }
Esempio n. 3
0
 /// <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));
 }
Esempio n. 4
0
 /// <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));
 }
Esempio n. 5
0
 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;
 }
Esempio n. 6
0
 public ActionResult New()
 {
     Buyer b = new Buyer();
     return View("New", new EditData(b, _metaProductRepo.CurrentMetaProduct));
 }
Esempio n. 7
0
 public UnsubscribeResult(Buyer buyer, bool success)
 {
     BuyerId = buyer.Id;
     BuyerName = buyer.FullName;
     Success = success;
 }
Esempio n. 8
0
 public EditData(Buyer b, MetaProduct mp)
 {
     Buyer = b;
     CurrentMetaProduct = mp;
 }
Esempio n. 9
0
 private void SetErrors(Buyer b)
 {
     Contract.Assert(b.HasErrors, "Set errors passed a valid entity.");
     SetModelErrors(b, "Save failed.");
 }
Esempio n. 10
0
        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;
            }
        }
Esempio n. 11
0
 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);
 }
Esempio n. 12
0
 public static string BuyerRowClass(Buyer b)
 {
     return (b.IsUnsubscribed) ? "unsubscribed" : String.Empty;
 }
Esempio n. 13
0
 partial void DeleteBuyer(Buyer instance);
Esempio n. 14
0
 partial void UpdateBuyer(Buyer instance);
Esempio n. 15
0
 partial void InsertBuyer(Buyer instance);