Ejemplo n.º 1
0
        public static ProductDetailModel Run(int storeId, long productId)
        {
            var parallelOptions = new ParallelOptions();

            parallelOptions.MaxDegreeOfParallelism = AppSettings.GetProductMaxDegreeOfParallelism.Value;

            using (var db = AliShopEntities.New())
            {
                var parameterRules   = RulesCreator.NewRules <AliParameterRules>(db);
                var productLinkRules = RulesCreator.NewRules <AliProductLinkRules>(db);

                var productUrl = parameterRules.GetByName("product_url").Value;

                var model = new GetProductModel
                {
                    ProductId = productId,
                    RefName   = productId.ToString(),
                    Url       = productUrl
                                .Replace("{store_id}", storeId.ToString())
                                .Replace("{product_id}", productId.ToString())
                };

                return(AliExpress.GetProductJSON(model));
            }
        }
Ejemplo n.º 2
0
 private static Product ConvertToProduct(GetProductModel model)
 {
     return(new Product
     {
         Id = model.Id,
         Brand = model.Brand,
         Image = model.Image,
         Price = model.Price,
         Title = model.Title
     });
 }
Ejemplo n.º 3
0
        public static bool Run(bool suppressHeader)
        {
            ChangeOutputType();

            if (!suppressHeader)
            {
                Print.PrintText("AliGetProduct", "");

                Console.WriteLine();
            }

            var productId  = Argument.GetArgumentLong("-ProductId");
            var storeId    = Argument.GetArgumentInt("-StoreId");
            var productUrl = Argument.GetArgumentString("-ProductUrl");

            var model = default(GetProductModel);

            if (productId.HasValue && storeId.HasValue)
            {
                model = new GetProductModel
                {
                    ProductId = productId.Value,
                    RefName   = productId.Value.ToString(),
                    Url       = AppSettings.AliExpressProductDetailUrl
                                .Replace("{store_id}", storeId.Value.ToString())
                                .Replace("{product_id}", productId.Value.ToString())
                };
            }
            else if (productUrl != null)
            {
                model = new GetProductModel
                {
                    ProductId = -1,
                    RefName   = "-1",
                    Url       = productUrl
                };
            }
            else
            {
                Print.PrintText("AliGetProduct", "Use -ProductId={{value}} -StoreId={{value}} or -ProductUrl={{value}}");

                return(false);
            }

            var details = GetProductDetails(model);

            Console.Write(JsonConvert.SerializeObject(details, Formatting.Indented));

            return(true);
        }
Ejemplo n.º 4
0
        public static ProductDetailModel GetProductDetails(GetProductModel item)
        {
            var job = new Job(item.Url, AliExpressProductScript);

            Program.Try(item.RefName, item.Url, 3, () => job.Run());

            var productDetail = default(ProductDetailModel);

            if (job.ReturnedJSON != null)
            {
                productDetail = JsonConvert.DeserializeObject <ProductDetailModel>(job.ReturnedJSON);
            }
            else
            {
                Print.PrintStatus(item.RefName, "Error", item.Url + Environment.NewLine + job.ReturnedValue, ConsoleColor.Red);
            }

            return(productDetail);
        }
Ejemplo n.º 5
0
        public IActionResult GetProducts(int page)
        {
            try
            {
                int itemsShow    = 4;
                var listProducts = _context.Products.AsQueryable();

                int countOfItems = listProducts.Count();

                listProducts = listProducts.Include(x => x.Category)
                               //.OrderBy(x=>x.Name)
                               .Skip((page - 1) * itemsShow)
                               .Take(itemsShow);
                var products = new List <ProductItemModel>();
                foreach (var item in listProducts)
                {
                    products.Add(new ProductItemModel
                    {
                        CategoryName = item.Category.Name,
                        ProductName  = item.Name,
                        ProductID    = item.Id
                    });
                }

                var model = new GetProductModel
                {
                    CurrentPage  = page,
                    CountOfPages = (int)Math.Ceiling((double)countOfItems / itemsShow),
                    Products     = products
                };

                return(Ok(model));
            }
            catch
            {
                return(BadRequest("Failed to get data!!!"));
            }
        }