/// <summary> /// Add to Cart method /// </summary> /// <param name="Page">page you are coming from</param> /// <param name="index">index of item to be added</param> /// <returns></returns> public ActionResult ATC(string Page, int index) { //If user is logged in otherwise no adding if (Session["UserId"] != null) { //Filling the cart from its JSON StoreFront.CustomerCart = Models.Files.WorkingWithJSON <Models.Cart.CartItem> .GetCartData((int)(Session["UserId"]), 0); //If that file was empty or did not exsist give a brand new customer cart if (StoreFront.CustomerCart == null) { StoreFront.CustomerCart = new List <Models.Cart.CartItem>(); } //Finds item based on its id and if it matches the index of the item sougt after Models.StoreItem.Furniture item = StoreFront.StoreStock.Find(x => x.id == index); //Makes furniture object into Cartitems Models.Cart.CartItem cartItem = new Models.Cart.CartItem((int)item.id, item.Name, item.Price, 1, item.ImageLink, item.Room) { //Adds the stock since it is not part of the constructor Stock = item.Stock }; //Atempt to put item in cart Models.Cart.CartItem.AddToCart(cartItem, StoreFront.CustomerCart); //create or change the Session variable used later Session["Count"] = StoreFront.CustomerCart.Count; //Saves new data Models.Files.WorkingWithJSON <Models.Cart.CartItem> .SaveCartData(StoreFront.CustomerCart, (int)(Session["UserId"])); } return(RedirectToAction("Index", Page)); }
/// <summary> /// Displays A specefied Product /// </summary> /// <param name="id">id of the product to be displayed</param> /// <returns></returns> public ActionResult Product(int id = 1) { //Finds first of product id Models.StoreItem.Furniture Product = StoreFront.StoreStock.Find(x => x.id == id); return(View(Product)); }