Exemple #1
0
        //______________________________________________________________________________________

        /// <summary>
        /// Product/EmptyCart/abd
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>

        public ActionResult EmptyCart(string id)
        {
            try
            {
                if (Session["usertype"] != null)
                {
                    string LoggedInUser = @User.Identity.Name;
                    ShoppingCartImplementation.EmptyCart(id);

                    return(RedirectToAction("Cart", "Product"));
                }
                else
                {
                    return(RedirectToAction("Cart", "Product"));
                }
            }
            catch (Exception ex)
            {
                bool rethrow = ExceptionPolicy.HandleException(ex, "UI Policy");
                if (rethrow)
                {
                    throw;
                }
                return(RedirectToAction("Index", "Product"));
            }
        }
Exemple #2
0
        //______________________________________________________________________________________

        /// <summary>
        /// Product/RemoveFromFrontCart/5
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>

        public ActionResult RemoveFromFrontCart(int id)
        {
            try
            {
                if (Session["usertype"] != null)
                {
                    string LoggedInUser = @User.Identity.Name;
                    ShoppingCartImplementation.RemoveFromCart(id, LoggedInUser);
                    return(RedirectToAction("Index", "Product" /*, new { id = LoggedInUser }*/));
                }
                else
                {
                    return(RedirectToAction("Index", "Product"));
                }
            }
            catch (Exception ex)
            {
                bool rethrow = ExceptionPolicy.HandleException(ex, "UI Policy");
                if (rethrow)
                {
                    throw;
                }
                return(RedirectToAction("Index", "Product"));
            }
        }
Exemple #3
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));
        }
Exemple #4
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));
        }
Exemple #5
0
        //______________________________________________________________________________________

        /// <summary>
        /// Product/Cart
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>

        public ActionResult DecrementQuantityFront(int id)
        {
            try
            {
                ShoppingCartImplementation.ReduceFromCart(id, @User.Identity.Name);
                return(RedirectToAction("Index", "Product"));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "Product"));
            }
        }
Exemple #6
0
        //______________________________________________________________________________________

        /// <summary>
        /// Product/Cart
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>

        public ActionResult IncrementQuantity(int id)
        {
            try
            {
                ShoppingCartImplementation.AddToCart(id, @User.Identity.Name);
                return(RedirectToAction("Cart", "Product"));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Cart", "Product"));
            }
        }
Exemple #7
0
        public ActionResult CheckOut(CheckOutModel checkout)
        {
            try
            {
                checkout.userdata.UserId = @User.Identity.Name;

                ViewBag.checkOutMessage = LetsShopImplementation.PlaceOrder(checkout);
                ShoppingCartImplementation.EmptyCart(@User.Identity.Name);
                return(View());
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
Exemple #8
0
        //______________________________________________________________________________________

        /// <summary>
        /// Product/Cart
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>

        public ActionResult DecrementQuantityFront(int id)
        {
            try
            {
                ShoppingCartImplementation.ReduceFromCart(id, @User.Identity.Name);
                return(RedirectToAction("Index", "Product"));
            }
            catch (Exception ex)
            {
                bool rethrow = ExceptionPolicy.HandleException(ex, "UI Policy");
                if (rethrow)
                {
                    throw;
                }
                return(RedirectToAction("Index", "Product"));
            }
        }
Exemple #9
0
        //______________________________________________________________________________________

        /// <summary>
        /// Product/Cart
        /// </summary>
        /// <returns></returns>

        public ActionResult Cart()
        {
            try
            {
                if (Session["usertype"] != null)
                {
                    return(View(ShoppingCartImplementation.GetFromCart(@User.Identity.Name)));
                }
                else
                {
                    return(RedirectToAction("Index", "Product"));
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "Product"));
            }
        }
Exemple #10
0
        //TESTING ITEMS ADDED TO CART WHEN THE QUANTITY INCREASES.
        public void AddToCartTest()
        {
            string UserId = "ashaka";
            List <AddToCartModel> list = new List <AddToCartModel>();

            list = ShoppingCartImplementation.GetFromCart(UserId);
            int    pid      = 5;
            int    quantity = GetQuantityFromId(pid, list);
            string actual;

            actual = ShoppingCartImplementation.AddToCart(pid, UserId);
            List <AddToCartModel> list1 = new List <AddToCartModel>();

            list1 = ShoppingCartImplementation.GetFromCart(UserId);
            int x = GetQuantityFromId(pid, list1);

            Assert.AreEqual(x, quantity + 1);
        }
Exemple #11
0
        public void RemoveFromCartTest()
        {
            string UserId = "ashaka";
            List <AddToCartModel> list = new List <AddToCartModel>();

            list = ShoppingCartImplementation.GetFromCart(UserId);
            int    x  = list.Count;
            int    id = 5;
            string actual;

            actual = ShoppingCartImplementation.RemoveFromCart(id, UserId);
            List <AddToCartModel> list1 = new List <AddToCartModel>();

            list1 = ShoppingCartImplementation.GetFromCart(UserId);
            int y = list1.Count;

            Assert.AreEqual(y + 1, x);
        }
Exemple #12
0
        //______________________________________________________________________________________

        /// <summary>
        /// Product/RemoveFromCart/5
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>

        public ActionResult RemoveFromCart(int id)
        {
            try
            {
                if (Session["usertype"] != null)
                {
                    string LoggedInUser = @User.Identity.Name;
                    ShoppingCartImplementation.RemoveFromCart(id, LoggedInUser);
                    return(RedirectToAction("Cart", "Product" /*, new { id = LoggedInUser }*/));
                }
                else
                {
                    return(RedirectToAction("Index", "Product"));
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "Product"));
            }
        }
Exemple #13
0
        public ActionResult CheckOut(CheckOutModel checkout)
        {
            try
            {
                checkout.userdata.UserId = @User.Identity.Name;

                ViewBag.checkOutMessage = LetsShopImplementation.PlaceOrder(checkout);
                ShoppingCartImplementation.EmptyCart(@User.Identity.Name);
                return(View());
            }
            catch (Exception ex)
            {
                bool rethrow = ExceptionPolicy.HandleException(ex, "UI Policy");
                if (rethrow)
                {
                    throw;
                }
                return(View());
            }
        }
Exemple #14
0
        //______________________________________________________________________________________

        /// <summary>
        /// Product/EmptyCart/abd
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>

        public ActionResult EmptyCart(string id)
        {
            try
            {
                if (Session["usertype"] != null)
                {
                    string LoggedInUser = @User.Identity.Name;
                    ShoppingCartImplementation.EmptyCart(id);

                    return(RedirectToAction("Cart", "Product"));
                }
                else
                {
                    return(RedirectToAction("Cart", "Product"));
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "Product"));
            }
        }
Exemple #15
0
        //______________________________________________________________________________________

        /// <summary>
        /// Product/Cart
        /// </summary>
        /// <returns></returns>

        public ActionResult Cart()
        {
            try
            {
                if (Session["usertype"] != null)
                {
                    return(View(ShoppingCartImplementation.GetFromCart(@User.Identity.Name)));
                }
                else
                {
                    return(RedirectToAction("Index", "Product"));
                }
            }
            catch (Exception ex)
            {
                bool rethrow = ExceptionPolicy.HandleException(ex, "UI Policy");
                if (rethrow)
                {
                    throw;
                }
                return(RedirectToAction("Index", "Product"));
            }
        }
Exemple #16
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"));
            }
        }