Exemplo n.º 1
0
        /// <summary>
        ///  GET: /Product/
        /// </summary>
        /// <returns></returns>

        public ActionResult Index(int?page)
        {
            List <int> orderidlist = new List <int>();

            List <AddToCartModel> cartlist = ShoppingCartImplementation.GetFromCart(@User.Identity.Name);

            CartAndAllProducts cp = new CartAndAllProducts();

            foreach (var x in cartlist)
            {
                orderidlist.Add(x.Product.ProductId);
            }
            ViewBag.Message = orderidlist;

            List <Product> productcacheData = new List <Product>();

            productcacheData = (List <Product>)cache["ProductData"];

            if (productcacheData == null)
            {
                cache.Add("ProductData", LetsShopImplementation.GetProducts(),
                          CacheItemPriority.High, null, absolutetime);
                //productcacheData = (List<Product>)cache["ProductData"];
            }

            List <Product> prodlist = productcacheData;

            cp.productlist = prodlist;
            cp.cartlist    = cartlist;

            return(View(cp));
        }
Exemplo n.º 2
0
        /// <summary>
        ///  GET: /Product/
        /// </summary>
        /// <returns></returns>

        public ActionResult Index(int?page)
        {
            List <int> orderidlist = new List <int>();

            List <AddToCartModel> cartlist = ShoppingCartImplementation.GetFromCart(@User.Identity.Name);

            CartAndAllProducts cp = new CartAndAllProducts();

            foreach (var x in cartlist)
            {
                // orderidlist.Add(x.Product.ProductId);
            }
            ViewBag.Message = orderidlist;


            List <Product> prodlist = LetsShopImplementation.GetProducts();

            foreach (var product in prodlist)
            {
                var fileName  = product.Picture;
                var dataArray = product.PictureContent;

                if (dataArray != null && !System.IO.File.Exists(Server.MapPath("~/Images/" + fileName)))
                {
                    using (FileStream fileStream = new FileStream(Server.MapPath("~/Images/" + fileName), FileMode.Create))
                    {
                        //var dataArray = artikel.Artikel.Artikel_Afbeelding.Afbeelding.Contents;
                        // Write the data to the file, byte by byte.
                        for (int i = 0; i < dataArray.Length; i++)
                        {
                            fileStream.WriteByte(dataArray[i]);
                        }

                        // Set the stream position to the beginning of the file.
                        fileStream.Seek(0, SeekOrigin.Begin);

                        // Read and verify the data.
                        for (int i = 0; i < fileStream.Length; i++)
                        {
                            if (dataArray[i] != fileStream.ReadByte())
                            {
                            }
                        }
                        Console.WriteLine("The data was written to {0} " +
                                          "and verified.", fileStream.Name);
                    }
                }
                product.Picture = WebConfigurationManager.AppSettings["ImageUpload"] + fileName;
            }

            cp.productlist = prodlist;
            cp.cartlist    = cartlist;

            return(View(cp));
        }
Exemplo n.º 3
0
        public ActionResult Index(string ProductName)
        {
            try
            {
                if (!String.IsNullOrEmpty(ProductName))
                {
                    try
                    {
                        var product = LetsShopImplementation.SearchProduct(ProductName);


                        List <int> orderidlist = new List <int>();

                        CartAndAllProducts    cp       = new CartAndAllProducts();
                        List <AddToCartModel> cartlist = ShoppingCartImplementation.GetFromCart(@User.Identity.Name);
                        foreach (var x in cartlist)
                        {
                            // orderidlist.Add(x.Product.ProductId);
                        }
                        ViewBag.Message = orderidlist;

                        if (product == null)
                        {
                            return(RedirectToAction("Index", "Product"));
                        }
                        else // if productname = "Alienware", search for "Alen", "Alien" and "Alienware" reaches here.
                        {
                            cp.productlist = product;
                            cp.cartlist    = cartlist;

                            return(View(cp));
                        }
                    }
                    catch (Exception)
                    {
                        return(RedirectToAction("ErrorPage", "Product"));
                    }
                }
                else  // empty search reaches here.
                {
                    ViewBag.errormessage = " Enter a name to search the product!!";
                    List <int> orderidlist = new List <int>();

                    CartAndAllProducts    cp       = new CartAndAllProducts();
                    List <AddToCartModel> cartlist = ShoppingCartImplementation.GetFromCart(@User.Identity.Name);

                    var products = LetsShopImplementation.GetProducts();

                    foreach (var x in cartlist)
                    {
                        // orderidlist.Add(x.Product.ProductId);
                    }
                    ViewBag.Message = orderidlist;

                    cp.productlist = products;
                    cp.cartlist    = cartlist;

                    return(View(cp));
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("ErrorPage", "Product"));
            }
        }