Ejemplo n.º 1
0
        public ActionResult Index(string id)
        {
            JObject productData = api.GetProductById(id);

            if (productData == null)
            {
                return(RedirectToAction("Home", "Error"));
            }

            SingleProductModel product = api.CastProduct(productData);

            List <string> relatedProductIDs = api.GetRelatedProductsID(productData);

            List <SingleProductModel> relatedProducts = new List <SingleProductModel>();

            if (relatedProductIDs.Any())
            {
                // Three related products should be enough.
                for (int i = 0; i < 3; i++)
                {
                    JObject            relatedProductData = api.GetProductById(relatedProductIDs[i]);
                    SingleProductModel relatedProduct     = api.CastProduct(relatedProductData);
                    relatedProducts.Add(relatedProduct);
                }
            }

            ProductViewModel model = new ProductViewModel
            {
                product         = product,
                relatedProducts = relatedProducts
            };

            return(View(model));
        }
        public void TestCastProduct()
        {
            ProductApp.Utils.ApiIntegration api = new ProductApp.Utils.ApiIntegration();

            JObject            productData = api.GetProductById("1000006");
            SingleProductModel product     = api.CastProduct(productData);

            Assert.IsNotNull(product);
            Assert.IsInstanceOfType(product, typeof(SingleProductModel));
        }
        public async Task <IActionResult> Index(int?id)
        {
            if (id != null)
            {
                int     langId  = HttpContext.GetLanguage("langId");
                Product product = await db.Products.Where(p => p.Id == id).FirstOrDefaultAsync();

                product.Rate = await CalcProductRateAsync(product);

                SingleProductModel model = new SingleProductModel()
                {
                    ProductLanguage = await db.ProductLanguages
                                      .Where(pl => pl.ProductId == id && pl.LanguageId == langId)
                                      .FirstOrDefaultAsync(),

                    //ProductColors = await db.ProductColors
                    //                                .Where(pc => pc.ProductId == id)
                    //                                        .Include(cl => cl.Color)
                    //                                                .ToListAsync(),

                    ProductSizeCount = await db.ProductSizeCounts
                                       .Where(ps => ps.ProductId == id)
                                       .Include(ps => ps.Size)
                                       .ToListAsync(),
                    ProductPhotos = await db.ProductPhotos
                                    .Where(pp => pp.Product == product)
                                    .ToListAsync(),
                    Product        = product,
                    ProductReviews = await db.ProductReviews
                                     .Where(pr => pr.ProductId == product.Id)
                                     .Include(pr => pr.User)
                                     .ToListAsync(),

                    ColorLanguages = await db.ColorLanguage
                                     .Where(cl => cl.LanguageId == langId)
                                     .Include(cl => cl.Color)
                                     .ToListAsync()
                };

                HttpContext.Session.SetString("product_id", id.ToString());
                return(View(model));
            }
            else
            {
                return(RedirectToAction("Error", "Home"));
            }
        }
        public ActionResult SingleProduct(int id)
        {
            KodmarkData data = new KodmarkData();

            var currentLanguage      = System.Threading.Thread.CurrentThread.CurrentCulture.Name;
            SingleProductModel model = new SingleProductModel();

            model = _data.singleProductModelsTr.FirstOrDefault(i => i.ProductId == id);

            switch (currentLanguage)
            {
            case "tr":
                model = _data.singleProductModelsTr.FirstOrDefault(i => i.ProductId == id);
                break;

            case "en":
                model = _data.singleProductModels.FirstOrDefault(i => i.ProductId == id);
                break;
            }


            return(View(model));
        }
Ejemplo n.º 5
0
        /// <inheritdoc/>
        public SingleProductModel CastProduct(JObject product)
        {
            string reviewCount = product["customerReviewCount"].ToString();

            if (string.IsNullOrEmpty(reviewCount))
            {
                reviewCount = "0";
            }

            string averageScore = product["customerReviewAverage"].ToString();

            if (string.IsNullOrEmpty(averageScore))
            {
                averageScore = "0";
            }

            string Image = product["largeImage"].ToString();

            if (string.IsNullOrEmpty(Image))
            {
                Image = product["thumbnailImage"].ToString();
            }

            SingleProductModel castedProduct = new SingleProductModel
            {
                SKU                = product["sku"].ToString(),
                Name               = product["name"].ToString(),
                Image              = Image,
                RegularPrice       = decimal.Parse(product["regularPrice"].ToString()),
                SalePrice          = decimal.Parse(product["salePrice"].ToString()),
                ReviewCount        = int.Parse(reviewCount),
                AverageReviewScore = float.Parse(averageScore, CultureInfo.InvariantCulture.NumberFormat),
                Description        = product["longDescription"].ToString()
            };

            return(castedProduct);
        }