Esempio n. 1
0
        /// <summary>
        ///     Return true if both objects are equal. Otherwise false.
        /// </summary>
        /// <param name="other">The other option selections</param>
        /// <returns></returns>
        public bool Equals(OptionSelections other)
        {
            var areEqual = OptionSelectionList.Equals(other.OptionSelectionList);

            if (areEqual)
            {
                foreach (var opSel in BundleSelectionList)
                {
                    var otherOpSelValue =
                        other.BundleSelectionList.Where(os => os.Key == opSel.Key)
                        .Select(os => os.Value)
                        .FirstOrDefault();
                    if (otherOpSelValue == null)
                    {
                        areEqual = false;
                        break;
                    }
                    areEqual &= opSel.Value.Equals(otherOpSelValue);
                    if (!areEqual)
                    {
                        break;
                    }
                }
            }
            return(areEqual);
        }
Esempio n. 2
0
        public void DeserializeFromXml(string xml)
        {
            if (string.IsNullOrEmpty(xml))
            {
                return;
            }

            try
            {
                Clear();

                var sr  = new StringReader(xml);
                var doc = XDocument.Load(sr);

                var selections = doc.XPathSelectElements("/OptionSelections/OptionSelection").
                                 Select(os => new
                {
                    OptionBvin    = os.Element("OptionBvin").Value,
                    SelectionData = os.Element("SelectionData").Value
                });

                foreach (var selection in selections)
                {
                    var sel = new OptionSelection();
                    sel.OptionBvin    = selection.OptionBvin;
                    sel.SelectionData = selection.SelectionData;
                    OptionSelectionList.Add(sel);
                }

                var bundleSelections = doc.XPathSelectElements("/OptionSelections/OptionSelections");

                foreach (var bundleSelection in bundleSelections)
                {
                    var bundledProductIdString = bundleSelection.Attribute("BundledProductId").Value;
                    var bundledProductId       = long.Parse(bundledProductIdString);
                    BundleSelectionList[bundledProductId] = new OptionSelectionList();

                    selections = bundleSelection.XPathSelectElements("OptionSelection").
                                 Select(os => new
                    {
                        OptionBvin    = os.Element("OptionBvin").Value,
                        SelectionData = os.Element("SelectionData").Value
                    });

                    foreach (var selection in selections)
                    {
                        var sel = new OptionSelection();
                        sel.OptionBvin    = selection.OptionBvin;
                        sel.SelectionData = selection.SelectionData;
                        GetSelections(bundledProductId).Add(sel);
                    }
                }
            }
            catch (Exception ex)
            {
                Clear();
                EventLog.LogEvent(ex);
            }
        }
Esempio n. 3
0
        public void AddBundleSelections(long bundledProductId, OptionSelection option)
        {
            if (!BundleSelectionList.Keys.Contains(bundledProductId))
            {
                BundleSelectionList[bundledProductId] = new OptionSelectionList();
            }

            BundleSelectionList[bundledProductId].Add(option);
        }
Esempio n. 4
0
 public Variant()
 {
     StoreId    = 0;
     Bvin       = string.Empty;
     ProductId  = string.Empty;
     Sku        = string.Empty;
     Price      = -1;
     Selections = new OptionSelectionList();
 }
Esempio n. 5
0
 private void SerializeOptionsListToXml(XmlTextWriter xw, OptionSelectionList optionSelectionList)
 {
     foreach (var sel in optionSelectionList)
     {
         xw.WriteStartElement("OptionSelection");
         xw.WriteElementString("OptionBvin", sel.OptionBvin);
         xw.WriteElementString("SelectionData", sel.SelectionData);
         xw.WriteEndElement();
     }
 }
Esempio n. 6
0
 /// <summary>
 ///     Outputs the HTML required to display this Option in the web page, with the default item selected, when appropriate.
 ///     This method uses the Processor property.
 /// </summary>
 /// <param name="selections">A listing of the default selections that should be made in the output HTML.</param>
 /// <param name="prefix">
 ///     (optional) When specified, this value will be included as a prefix to the Name attribute of the
 ///     rendered items.
 /// </param>
 /// <param name="className">When specified, the given class name will be appended to the controls rendered to the view.</param>
 /// <returns>
 ///     An HTML-friendly string representation of the Option, based upon its respective OptionType, with default
 ///     selections made.
 /// </returns>
 public string RenderWithSelection(OptionSelectionList selections, string prefix = null, string className = null)
 {
     if (prefix == null)
     {
         prefix = string.Empty;
     }
     if (className == null)
     {
         className = string.Empty;
     }
     return(Processor.RenderWithSelection(this, selections, prefix, className));
 }
Esempio n. 7
0
 /// <summary>
 ///     Return true if both objects are equal. Otherwise false.
 /// </summary>
 /// <param name="other">The other option selections</param>
 /// <returns></returns>
 public bool Equals(OptionSelectionList other)
 {
     foreach (var item in this)
     {
         var otherItem =
             other.FirstOrDefault(i => i.OptionBvin == item.OptionBvin && i.SelectionData == item.SelectionData);
         if (otherItem == null)
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 8
0
        public string CartDescription(OptionSelectionList selections)
        {
            var sb = new StringBuilder();

            sb.Append(UL_OPEN);
            foreach (var opt in this)
            {
                var desc = opt.CartDescription(selections);
                if (desc.Length > 0)
                {
                    sb.AppendFormat(LINE_ITEM, desc);
                }
            }
            sb.Append(UL_CLOSE);
            return(sb.ToString());
        }
Esempio n. 9
0
        public Variant FindBySelectionData(OptionSelectionList selections, OptionList options)
        {
            var variantSelections = new OptionSelectionList();

            foreach (var opt in options)
            {
                if (opt.IsVariant)
                {
                    var sel = selections.FindByOptionId(opt.Bvin);
                    if (sel != null)
                    {
                        variantSelections.Add(sel);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            var selectionKey = OptionSelection.GenerateUniqueKeyForSelections(variantSelections);

            return(FindByKey(selectionKey));
        }
Esempio n. 10
0
 /// <summary>
 ///     Allows you to return a value that contains the Option and a comma delimited list of its items for identifying in
 ///     the description of the Cart/Order. This is primarily called when a product is being converted to a line item for a
 ///     cart/order.
 /// </summary>
 /// <param name="selections">A parsed collection of the selections made on this Option.</param>
 /// <returns>A comma delimited string of the Option items preceded by the option name.</returns>
 public string CartDescription(OptionSelectionList selections)
 {
     return(Processor.CartDescription(this, selections));
 }
Esempio n. 11
0
 /// <summary>
 ///     Outputs the HTML required to display this Option in the web page, with the default item selected, when appropriate.
 ///     This method uses the Processor property.
 /// </summary>
 /// <param name="selections">A listing of the default selections that should be made in the output HTML.</param>
 /// <param name="prefix">
 ///     (optional) When specified, this value will be included as a prefix to the Name attribute of the
 ///     rendered items.
 /// </param>
 /// <returns>
 ///     An HTML-friendly string representation of the Option, based upon its respective OptionType, with default
 ///     selections made.
 /// </returns>
 public string RenderWithSelection(OptionSelectionList selections, string prefix = null)
 {
     return(Processor.RenderWithSelection(this, selections, prefix));
 }
Esempio n. 12
0
 public OptionSelections()
 {
     OptionSelectionList = new OptionSelectionList();
     BundleSelectionList = new Dictionary <long, OptionSelectionList>();
 }
Esempio n. 13
0
 public void Clear()
 {
     OptionSelectionList.Clear();
     BundleSelectionList.Clear();
 }