예제 #1
0
        public ProductView[] GetProducts()
        {
            List <ProductView> products = new List <ProductView>();

            var catalog = catalogApi.Get();

            if (catalog == null)
            {
                return(products.ToArray());
            }

            foreach (string id in catalog.ProductList)
            {
                var product = productApi.Get(id);
                if (product != null)
                {
                    products.Add(productConverter.Convert(product));
                }
            }
            return(products.ToArray());
        }
예제 #2
0
        public void Execute(ICommand T)
        {
            UpdateCommand command = T as UpdateCommand;

            if (command == null)
            {
                return;
            }
            var isbns = command.Isbns;

            for (int i = 0; i < isbns.Length / 10.0; i++)
            {
                var chunk = isbns.Skip(i * 10).Take(10).ToArray();


                var founded  = _unitOfWork.Repository.GetBooks().AsNoTracking().Where(x => isbns.Contains(x.Isbn13)).Select(x => x.Isbn13);
                var notFound = chunk.Except(founded).ToArray();
                var result   = _productApi.Get(notFound);
                if (result == null || !result.Any())
                {
                    continue;
                }

                foreach (var product in result)
                {
                    _unitOfWork.Add(new BookStore.Search.CommandStack.Model.Book()
                    {
                        Imageurl = product.imageurl,
                        Isbn13   = product.isbn13,
                        Title    = product.title,
                        Url      = product.url
                    });
                }
                _unitOfWork.Save();
            }
        }