public async Task <string> MineProduct(string url)
    {
        string pageContent = await HttpTools.DownloadPage(url);

        //get wallmart product details
        Product        product   = ExtractProduct(pageContent);
        BaseDataAccess bda       = new BaseDataAccess();
        int            productId = 0;

        if (!bda.ProductExists(product.SellerInternalId, out productId))
        {
            productId = (int)bda.AddProduct(product);
            if (productId > 0)
            {
                foreach (Review r in product.Reviews)
                {
                    bda.AddReview(productId, r);
                }
            }
        }
        else
        {
            bda.DeleteReviews(productId); //refill reviews
            foreach (Review r in product.Reviews)
            {
                bda.AddReview(productId, r);
            }
        }
        return(product.SellerInternalId);
    }
Exemplo n.º 2
0
    public async Task <string> MineProduct(string url)
    {
        string pageContent = await HttpTools.DownloadPage(url);

        //get wallmart number
        int    productNumberIndex    = pageContent.IndexOf("\"walmartItemNumber\"") + 22;
        int    productNumberEndIndex = pageContent.IndexOf("\"brand\"", productNumberIndex) - 3;
        string productNumber         = pageContent.Substring(productNumberIndex, productNumberEndIndex - productNumberIndex);

        using (DatabaseRpoundForestEntities db = new DatabaseRpoundForestEntities())
        {
            Product product = db.Products.Where((x) => x.SellerInternalId == productNumber).FirstOrDefault();
            if (product == null)     //add it
            {
                product = GetAndAddProduct(pageContent, productNumber, db);
            }

            //delete all reviews and re-fill
            DeleteGetAndAddReviews(product.Id, pageContent, db);
        }
        return(productNumber);
    }