public async Task<IActionResult> Index() { // Find user var userId = User.GetUserId(); ApplicationUser user = await _userManager.FindByIdAsync(userId); // Save userId to Viewbag if (userId != null) { ViewBag.UserId = userId; } // Check if user has a default list, otherwise add a new list to the user if (user.DefaultListId.ToString() == "0") { List newDefaultList = new List { UserId = userId }; _context.List.Add(newDefaultList); await _context.SaveChangesAsync(); user.DefaultListId = newDefaultList.ListId; await _userManager.UpdateAsync(user); } // Add ListId to the ViewBag. ViewBag.ListId = user.DefaultListId; ViewBag.DefaultListId = user.DefaultListId; return View(); }
// GET: ShoppingList public ActionResult Index() { //create shopping cart var customerCart = new List<Customer> { new Customer { FirstName = "Cave", LastName ="Johnson", Cart = new List<Product> { new Product {Name="Lemon", Price = 5.00m }, } }, new Customer { FirstName = "Chell", LastName = "Unknown", Cart = new List<Product> { new Product {Name="Portal Gun", Price = 9999.00m }, new Product {Name="Companion Cube", Price = 50.00m } } } }; var vm = new CustomerIndexViewModel { Customers = customerCart }; return View(vm); }
public async Task<IActionResult> Edit(List list) { if (ModelState.IsValid) { _context.Update(list); await _context.SaveChangesAsync(); return RedirectToAction("Index"); } return View(list); }
// GET: Customers public ActionResult Index() { List<Products> products = new List<Products> { new Products {Name = "Apple", Price = 1.99m}, new Products {Name = "Eggs", Price = 3.29m}, new Products {Name = "Ice Cream", Price = 4.99m} }; List<Customer> customer = new List<Customer> { new Customer { ListOfProducts = products, LastName = "Fleming", FirstName = "Jeremy"} }; IndexViewModel vm = new IndexViewModel { Customers = customer }; return View(vm); }
public Customer() { ListOfProducts = new List<Products>(); }
// GET: Products public ActionResult Index() { // create list of products var products = new List<Product> { new Product {Name="Milk", Price=2.33m}, new Product {Name="Eggs", Price=1.09m}, new Product {Name="Cheese", Price=12.00m} }; // assign products to view model var vm = new IndexViewModel { Products = products, FirstName = "Jay", LastName = "Schultz" }; // return view with view model return View(vm); }