public IActionResult Add(AddLaptopViewModel addLaptopViewModel) { if (ModelState.IsValid) { LaptopCategory newLaptopCategory = context.Categories.Single(c => c.ID == addLaptopViewModel.CategoryID); // Add new laptop to the list of existing laptops Laptop newLaptop = new Laptop { Name = addLaptopViewModel.Name, Description = addLaptopViewModel.Description, Category = newLaptopCategory }; context.Laptops.Add(newLaptop); context.SaveChanges(); return(Redirect("/Laptop")); } return(View(addLaptopViewModel)); }
public IActionResult Add() { AddLaptopViewModel addLaptopViewModel = new AddLaptopViewModel(context.Categories.ToList()); return(View(addLaptopViewModel)); }