Example #1
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);
            }
        }
Example #2
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));
        }