コード例 #1
0
    private void DeleteGetAndAddReviews(int productId, string pageContent, DatabaseRpoundForestEntities db)
    {
        //remove
        db.Reviews.RemoveRange(db.Reviews.Where(x => x.ProductId == productId));
        db.SaveChanges();
        //getcustomerReviews
        int    customerReviewsIndex    = pageContent.IndexOf("\"customerReviews\"") + 18;
        int    customerReviewsEndIndex = pageContent.IndexOf("\"selected\"", customerReviewsIndex) - 3;
        string reviewList  = pageContent.Substring(customerReviewsIndex, customerReviewsEndIndex - customerReviewsIndex);
        var    reviewList2 = JsonConvert.DeserializeObject <List <ReviewClass> >(reviewList);

        //List<ReviewShow> reviews = new List<ReviewShow>();
        foreach (ReviewClass rc in reviewList2)
        {
            var thisReview = new Review
            {
                ProductId   = productId,
                ReviewTitle = rc.reviewTitle,
                ReviewText  = rc.reviewText,
                Stars       = Convert.ToInt32(rc.rating)
            };
            db.Reviews.Add(thisReview);
            //reviews.Add(new ReviewShow { rating = rc.rating, reviewText = rc.reviewText, reviewTitle = rc.reviewTitle } );
        }
        db.SaveChanges();
    }
コード例 #2
0
    private Product GetAndAddProduct(string pageContent, string productNumber, DatabaseRpoundForestEntities db)
    {
        int     selectedProductIdIndex = pageContent.IndexOf("\"selectedProductId\"");
        int     productTitleIndex      = pageContent.IndexOf("\"title\"", selectedProductIdIndex) + 9;
        int     productTitleEndIndex   = pageContent.IndexOf("\"brand\"", selectedProductIdIndex) - 2;
        string  productTitle           = pageContent.Substring(productTitleIndex, productTitleEndIndex - productTitleIndex);
        Product newProduct             = new Product {
            SellerInternalId = productNumber, ProductName = productTitle, Price = 22.33M
        };

        db.Products.Add(newProduct);     //and whatever the price is.
        db.SaveChanges();
        return(newProduct);
    }