// // GET: /Store/AddToCart/5 public ActionResult AddToCart(int id) { // Retrieve the album from the database var addedAlbum = _context.Albums .Single(album => album.AlbumId == id); var currentCart = _context.Carts.Where(x => x.AlbumId == addedAlbum.AlbumId).Where(x => x.CartId == userID).FirstOrDefault(); var cart = new Cart() { }; if (currentCart == null) //new cart { cart.CartId = userID; cart.AlbumId = id; cart.Album = addedAlbum; cart.DateCreated = DateTime.Now; cart.Count = cart.Count + 1; _context.Carts.Add(cart); } else { currentCart.Count = currentCart.Count + 1; _context.Update(currentCart); } _context.SaveChanges(); // Add it to the shopping cart //var cart = ShoppingCart.GetCart(_context); //cart.AddToCart(addedAlbum); // Go back to the main store page for more shopping return(RedirectToAction("Index")); }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new TOTVSContext( serviceProvider.GetRequiredService <DbContextOptions <TOTVSContext> >())) { // Look for any Client. if (context.Produto.Any()) { return; // DB has been seeded } context.Produto.AddRange( new Produto { Descricao = "Produto Seeded 1", Valor = 12.51f }, new Produto { Descricao = "Produto Seeded 2", Valor = 13.00f }, new Produto { Descricao = "Produto Seeded 3", Valor = 15f }, new Produto { Descricao = "Produto Seeded 3", Valor = 55.43f }, new Produto { Descricao = "Produto Seeded 3", Valor = 7348.99f } ); context.SaveChanges(); } }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new TOTVSContext( serviceProvider.GetRequiredService <DbContextOptions <TOTVSContext> >())) { // Look for any Client. if (context.Cliente.Any()) { return; // DB has been seeded } context.Cliente.AddRange( new Cliente { Nome = "Cliente Generico", CPF = "23340128073" } ); context.SaveChanges(); } }