public async Task <IActionResult> Edit(int id, [Bind("ID,ValorTotal")] Pedido pedido) { if (id != pedido.PedidoID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(pedido); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PedidoExists(pedido.PedidoID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(pedido)); }
public async Task <IActionResult> Edit(int id, [Bind("AlbumId,GenreId,ArtistId,Title,Price,AlbumArtUrl")] Album album) { if (id != album.AlbumId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(album); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AlbumExists(album.AlbumId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ArtistId"] = new SelectList(_context.Artists, "ArtistId", "ArtistId", album.ArtistId); ViewData["GenreId"] = new SelectList(_context.Genres, "GenreId", "GenreId", album.GenreId); return(View(album)); }
public async Task <IActionResult> Edit(int id, [Bind("UserID,Nome,CPF")] User user) { if (id != user.UserID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(user); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(user.UserID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(user)); }
// // 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")); }