public IActionResult Add(AddWishListViewModel addWishListViewModel) { if (ModelState.IsValid) { WishList newWishList = new WishList { Name = addWishListViewModel.Name }; context.WishLists.Add(newWishList); context.SaveChanges(); return(Redirect("/WishList")); } return(View(addWishListViewModel)); }
public static void Initialise(IServiceProvider serviceProvider) { using (var context = new LaptopDbContext(serviceProvider.GetRequiredService <DbContextOptions <LaptopDbContext> >())) { if (context.Laptops.Any()) { return; } else { context.Laptops.AddRange( new Laptop { Id = new Guid("9ba0aea2-ec32-4cc9-90a3-a2f70895fdaf"), Name = "Dell", Price = 349.87M }, new Laptop { Id = new Guid("ab147a3e-f10f-4be5-a403-b22202aa663b"), Name = "Toshiba", Price = 345.67M }, new Laptop { Id = new Guid("d55588ad-52b5-4a36-a071-903be399d62d"), Name = "HP", Price = 456.76M } ); } context.SaveChanges(); } }
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(AddCategoryViewModel addCategoryViewModel) { if (ModelState.IsValid) { LaptopCategory newCategory = new LaptopCategory { Name = addCategoryViewModel.Name }; context.Categories.Add(newCategory); context.SaveChanges(); return(Redirect("/Category")); } return(View(addCategoryViewModel)); }