/// <summary>
        /// Parses the XML from a CMS Product List and returns a list of SkuPidCatalog objects.
        /// </summary>
        private SkuPidCatalog[] ParseCmsProductList(string xml)
        {
            var skuPidCatalogs = new List <SkuPidCatalog>();

            // Ensure content has the root element.
            if (!xml.StartsWith("<root"))
            {
                xml = string.Format("<root>{0}</root>", xml);
            }

            var root     = XElement.Load(new StringReader(xml));
            var products = root.Elements("ProductList").Elements("Product");

            foreach (var product in products)
            {
                var sku     = product.Element("ProductId").Value;
                var catalog = product.Element("Catalog").Value;

                if (!string.IsNullOrWhiteSpace(sku) && !string.IsNullOrWhiteSpace(catalog))
                {
                    skuPidCatalogs.Add(new SkuPidCatalog
                    {
                        Sku     = sku,
                        Pid     = ISBNUtils.ConvertUPCToPID(sku),
                        Catalog = catalog
                    });
                }
            }

            return(skuPidCatalogs.ToArray());
        }
        public AddEntityViewModel()
        {
            using (var context = new BookOrdersContext()) {
                Books          = new ObservableCollection <Book>(context.Books);
                Authors        = new ObservableCollection <Author>(context.Authors);
                Publishers     = new ObservableCollection <Publisher>(context.Publishers);
                NewPublisherId = (int)context.Database.SqlQuery <decimal>("SELECT last_value FROM publishers_id_seq")
                                 .First() + 1;
            }

            NewBook          = new Book();
            NewAuthor        = new Author();
            NewPublisher     = new Publisher();
            NewBookAndAuthor = new BookAndAuthor();
            NewBook.InitializeValidator(null, new List <Publisher>(Publishers)
            {
                new Publisher {
                    Id = NewPublisherId
                }
            });
            NewAuthor.InitializeValidator();
            NewPublisher.InitializeValidator();
            NewBookAndAuthor.InitializeValidator();
            AddNewEntityCommand      = new DelegateCommand <object>(AddNewEntity, CanAddNewEntity);
            NewBook.PropertyChanged += delegate {
                if (NewBook.Validator.IsValid)
                {
                    NewPublisher.Id = ISBNUtils.GetPublisherId(NewBook.ISBN);
                }
            };

            NewPublisher.PropertyChanged += OnNewPublisherOnPropertyChanged;
        }