/// <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)); }
/// <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)); }
//______________________________________________________________________________________ /// <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")); } }
//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); }
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); }
//______________________________________________________________________________________ /// <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")); } }
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")); } }