public IActionResult Index(BrandViewModel vm) { // Only build the catalogue once if (HttpContext.Session.Get <List <Brand> >(SessionVars.Brands) == null) { // no session information so let's go to the database try { BrandModel categoryModel = new BrandModel(_db); // now load the categories List <Brand> categories = categoryModel.GetAll(); HttpContext.Session.Set <List <Brand> >(SessionVars.Brands, categories); vm.SetBrands(categories); } catch (Exception ex) { ViewBag.Message = "Catalogue Problem - " + ex.Message; } } else { // no need to go back to the database as information is already in the session vm.SetBrands(HttpContext.Session.Get <List <Brand> >(SessionVars.Brands)); ProductModel itemModel = new ProductModel(_db); vm.Products = itemModel.GetAllByBrand(vm.BrandId); } return(View(vm)); }
public IActionResult Index(BrandViewModel vm) { // only build the catalogue once if (HttpContext.Session.Get <List <Brand> >("brands") == null) { // no session information so let's go to the database try { BrandModel brandModel = new BrandModel(_db); // now load the categories List <Brand> brands = brandModel.GetAll(); HttpContext.Session.Set <List <Brand> >("brands", brands); vm.SetBrands(brands); } catch (Exception ex) { ViewBag.Message = "Catalogue Problem - " + ex.Message; } } else { // no need to go back to the database as information is already in the session vm.SetBrands(HttpContext.Session.Get <List <Brand> >("brands")); } return(View(vm)); }
public IActionResult SelectBrand(BrandViewModel vm) { BrandModel brandModel = new BrandModel(_db); ProductModel productModel = new ProductModel(_db); List <Product> items = productModel.GetAllByBrand(vm.BrandId); List <ProductViewModel> vms = new List <ProductViewModel>(); if (items.Count > 0) { foreach (Product item in items) { ProductViewModel mvm = new ProductViewModel(); mvm.Qty = 0; mvm.BrandId = item.BrandId; mvm.BrandName = brandModel.GetName(item.BrandId); mvm.Description = item.Description; mvm.Id = item.Id; mvm.PRODUCTNAME = item.ProductName; mvm.GRAPHICNAME = item.GraphicName; mvm.COSTPRICE = Convert.ToDecimal(item.CostPrice); mvm.MSRP = Convert.ToDecimal(item.MSRP); mvm.QTYONHAND = item.QtyOnHand; mvm.QTYONBACKORDER = item.QtyOnBackOrder; vms.Add(mvm); } ProductViewModel[] myMenu = vms.ToArray(); HttpContext.Session.Set <ProductViewModel[]>("menu", myMenu); } vm.SetBrands(HttpContext.Session.Get <List <Brand> >("brands")); return(View("Index", vm)); // need the original Index View here }
public IActionResult SelectBrand(BrandViewModel vm) { BrandModel brandModel = new BrandModel(_db); ProductModel prodModel = new ProductModel(_db); List <Product> items = prodModel.GetAllByBrand(vm.BrandId); List <ProductViewModel> vms = new List <ProductViewModel>(); if (items.Count > 0) { foreach (Product item in items) { ProductViewModel mvm = new ProductViewModel(); mvm.Qty = 0; mvm.BrandId = item.BrandId; mvm.BrandName = brandModel.GetName(item.BrandId); mvm.GraphicName = item.GraphicName; mvm.ProductName = item.ProductName; mvm.MSRP = item.MSRP; mvm.QtyOnHand = item.QtyOnHand; mvm.QtyOnBackOrder = item.QtyOnBackOrder; mvm.Description = item.Description; mvm.Id = item.Id; mvm.CostPrice = item.CostPrice; vms.Add(mvm); } ProductViewModel[] myProduct = vms.ToArray(); HttpContext.Session.Set <ProductViewModel[]>("product", myProduct); } vm.SetBrands(HttpContext.Session.Get <List <Brand> >("brands")); return(View("Index", vm)); // need the original Index View here }
public IActionResult SelectBrand(BrandViewModel vm) { BrandModel bmModel = new BrandModel(_db); ProductModel pModel = new ProductModel(_db); List <Product> items = pModel.GetAllByBrand(vm.BrandId); List <ProductViewModel> vms = new List <ProductViewModel>(); if (items.Count > 0) { foreach (Product pr in items) { ProductViewModel pvm = new ProductViewModel(); pvm.Qty = 0; pvm.BrandId = pr.BrandId; pvm.Id = pr.Id; // Id is a string pvm.BrandName = bmModel.GetName(pr.BrandId); pvm.ProductName = pr.ProductName; pvm.GraphicName = pr.GraphicName; pvm.CostPrice = pr.CostPrice; pvm.MSRP = pr.MSRP; pvm.QtyOnHand = pr.QtyOnHand; pvm.QtyOnBackOrder = pr.QtyOnBackOrder; pvm.Description = pr.Description; vms.Add(pvm); } ProductViewModel[] myProducts = vms.ToArray(); HttpContext.Session.Set <ProductViewModel[]>(SessionVariables.Catalogue, myProducts); } vm.SetBrands(HttpContext.Session.Get <List <Brand> >(SessionVariables.Brands)); return(View("Index", vm)); }
public IActionResult SelectBrand(BrandViewModel vm) { BrandModel brandModel = new BrandModel(_db); ProductModel productModel = new ProductModel(_db); List <Product> products = productModel.GetAllByBrand(vm.BrandId); List <ProductViewModel> productViewModels = new List <ProductViewModel>(); if (products.Count > 0) { foreach (Product product in products) { ProductViewModel productViewModel = new ProductViewModel(); productViewModel.Qty = 0; productViewModel.QtyOnBackOrder = product.QtyOnBackOrder; productViewModel.QtyOnHand = product.QtyOnHand; productViewModel.Description = product.Description; productViewModel.Id = product.Id; productViewModel.BrandName = brandModel.GetName(product.BrandId); productViewModel.GraphicName = product.GraphicName; productViewModel.CostPrice = product.CostPrice; productViewModel.MSRP = product.MSRP; productViewModel.BrandId = product.BrandId; productViewModel.ProductName = product.ProductName; productViewModels.Add(productViewModel); } ProductViewModel[] myItems = productViewModels.ToArray(); HttpContext.Session.Set <ProductViewModel[]>(SessionVars.Items, myItems); } vm.SetBrands(HttpContext.Session.Get <List <Brand> >(SessionVars.Brands)); return(View("Index", vm)); }
public ActionResult SelectItem(BrandViewModel brandVm) { // cs we change int to string Dictionary <string, object> tray; if (HttpContext.Session.Get <Dictionary <string, Object> >("tray") == null) { tray = new Dictionary <string, object>(); } else { tray = HttpContext.Session.Get <Dictionary <string, object> >("tray"); } ProductViewModel[] myProdArray = HttpContext.Session.Get <ProductViewModel[]>("productSession"); String retMsg = ""; foreach (ProductViewModel item in myProdArray) { if (item.Id == brandVm.ProductId) // change that to .productId { if (brandVm.QtyOnHand > 0) // update only selected item { item.QtyOnHand = brandVm.QtyOnHand; retMsg = brandVm.QtyOnHand + " - item(s) Added!"; tray[item.Id] = item; } else { item.QtyOnHand = 0; tray.Remove(item.Id); retMsg = "item(s) Removed!"; } brandVm.BrandId = item.BrandId; break; } } ViewBag.AddMessage = retMsg; HttpContext.Session.Set <Dictionary <string, Object> >("tray", tray); brandVm.SetBrands(HttpContext.Session.Get <List <Brands> >("brandSession")); return(View("Index", brandVm)); }
public ActionResult SelectItem(BrandViewModel vm) { Dictionary <string, object> tray; if (HttpContext.Session.Get <Dictionary <string, Object> >("tray") == null) { tray = new Dictionary <string, object>(); } else { tray = HttpContext.Session.Get <Dictionary <string, object> >("tray"); } ProductViewModel[] menu = HttpContext.Session.Get <ProductViewModel[]>("menu"); String retMsg = ""; foreach (ProductViewModel item in menu) { if (item.Id.Equals(vm.Id)) { if (vm.Qty > 0) // update only selected item { item.Qty = vm.Qty; retMsg = vm.Qty + " - item(s) Added!"; tray[item.Id] = item; } else { item.Qty = 0; tray.Remove(item.Id); retMsg = "item(s) Removed!"; } vm.BrandId = item.BrandId; break; } } ViewBag.AddMessage = retMsg; HttpContext.Session.Set <Dictionary <string, Object> >("tray", tray); vm.SetBrands(HttpContext.Session.Get <List <Brand> >("brands")); return(View("Index", vm)); }
public ActionResult SelectProduct(BrandViewModel vm) { Dictionary <string, object> cart; if (HttpContext.Session.Get <Dictionary <string, Object> >("cart") == null) { cart = new Dictionary <string, object>(); } else { cart = HttpContext.Session.Get <Dictionary <string, object> >("cart"); } ProductViewModel[] product = HttpContext.Session.Get <ProductViewModel[]>("product"); String retMsg = ""; foreach (ProductViewModel item in product) { if (item.Id == vm.Id) { if (vm.Qty > 0) // update only selected item { item.Qty = vm.Qty; retMsg = vm.Qty + " - item(s) Added!"; cart[item.Id] = item; } else { item.Qty = 0; cart.Remove(item.Id); retMsg = "item(s) Removed!"; } vm.BrandId = item.BrandId; break; } } ViewBag.AddMessage = retMsg; HttpContext.Session.Set <Dictionary <string, Object> >("cart", cart); vm.SetBrands(HttpContext.Session.Get <List <Brand> >("brands")); return(View("Index", vm)); }
public ActionResult SelectProduct(BrandViewModel vm) { Dictionary <string, object> order; if (HttpContext.Session.Get <Dictionary <string, Object> >(SessionVariables.Order) == null) { order = new Dictionary <string, object>(); } else { order = HttpContext.Session.Get <Dictionary <string, object> >(SessionVariables.Order); } ProductViewModel[] prdt = HttpContext.Session.Get <ProductViewModel[]>(SessionVariables.Product); String retMsg = ""; foreach (ProductViewModel item in prdt) { if (item.Id == vm.selectedId) { if (vm.Qty > 0) // update only selected item { item.Qty = vm.Qty; retMsg = vm.Qty + " - item(s) Added!"; order[item.Id] = item; } else { item.Qty = 0; order.Remove(item.Id); retMsg = "item(s) Removed!"; } vm.BrandId = item.BrandID; break; } } ViewBag.AddMessage = retMsg; HttpContext.Session.Set <Dictionary <string, Object> >(SessionVariables.Order, order); vm.SetBrands(HttpContext.Session.Get <List <Brand> >(SessionVariables.Brand)); return(View("Index", vm)); }
public ActionResult SelectProduct(BrandViewModel vm) { Dictionary <string, object> shoppingCart; if (HttpContext.Session.Get <Dictionary <string, Object> >(SessionVariables.Cart) == null) { shoppingCart = new Dictionary <string, object>(); } else { shoppingCart = HttpContext.Session.Get <Dictionary <string, object> >(SessionVariables.Cart); } ProductViewModel[] cart = HttpContext.Session.Get <ProductViewModel[]>(SessionVariables.Catalogue); String retMsg = ""; foreach (ProductViewModel item in cart) { if (item.Id == vm.ProductId) { if (vm.Qty > 0) // update only selected item { item.Qty = vm.Qty; retMsg = vm.Qty + " - item(s) Added!"; shoppingCart[item.Id] = item; } else { item.Qty = 0; shoppingCart.Remove(item.Id); retMsg = "item(s) Removed!"; } vm.BrandId = item.BrandId; break; } } ViewBag.AddMessage = retMsg; HttpContext.Session.Set <Dictionary <string, Object> >(SessionVariables.Cart, shoppingCart); vm.SetBrands(HttpContext.Session.Get <List <Brand> >(SessionVariables.Brands)); return(View("Index", vm)); }
public ActionResult SelectItem(BrandViewModel vm) { Dictionary <string, object> cart; if (HttpContext.Session.Get <Dictionary <string, Object> >(SessionVars.Cart) == null) { cart = new Dictionary <string, object>(); } else { cart = HttpContext.Session.Get <Dictionary <string, object> >(SessionVars.Cart); } ProductViewModel[] items = HttpContext.Session.Get <ProductViewModel[]>(SessionVars.Items); String retMsg = ""; foreach (ProductViewModel item in items) { if (item.Id == vm.SelectedProductId) { if (vm.Qty > 0) // update only selected item { item.Qty = vm.Qty; retMsg = vm.Qty + " - item(s) Added!"; cart[item.Id] = item; } else { item.Qty = 0; cart.Remove(item.Id); retMsg = "item(s) Removed!"; } vm.BrandId = item.BrandId; break; } } ViewBag.AddMessage = retMsg; HttpContext.Session.Set <Dictionary <string, Object> >(SessionVars.Cart, cart); vm.SetBrands(HttpContext.Session.Get <List <Brand> >(SessionVars.Brands)); return(PartialView("AddToCartPartial")); }
// to get the detial of product public IActionResult SelectBrand(BrandViewModel brandVm) { BrandModel brandModel = new BrandModel(_db); ProductModel prodModel = new ProductModel(_db); List <Product> productsListByBrand = prodModel.GetByBrand(brandVm.BrandId); List <ProductViewModel> prodVMList = new List <ProductViewModel>(); if (productsListByBrand.Count > 0) { // give me the details of each product by foreach loop foreach (Product prod in productsListByBrand) { ProductViewModel prodVM = new ProductViewModel(); prodVM.QtyOnHand = 0; prodVM.BrandId = prod.BrandId; prodVM.BrandName = brandModel.GetName(prod.BrandId); prodVM.Description = prod.Description; prodVM.CostPrice = prod.CostPrice; prodVM.Id = prod.Id; prodVM.GraphicName = prod.GraphicName; prodVM.MSRP = prod.MSRP; prodVM.ProductName = prod.ProductName; prodVM.QtyOnHand = prod.QtyOnHand; prodVM.QtyOnBackOrder = prod.QtyOnBackOrder; prodVMList.Add(prodVM); } ProductViewModel[] myProdArray = prodVMList.ToArray(); HttpContext.Session.Set <ProductViewModel[]>("productSession", myProdArray); } brandVm.SetBrands(HttpContext.Session.Get <List <Brands> >("brandSession")); return(View("Index", brandVm)); }