public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description,MinimumRequirements,Price,DeveloperId,GenreId,ImageUrl")] Game game) { if (id != game.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(game); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GameExists(game.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["DeveloperId"] = new SelectList(_context.Set <Developer>(), "DeveloperId", "DeveloperId", game.DeveloperId); ViewData["GenreId"] = new SelectList(_context.Set <Genre>(), "GenreId", "Description", game.GenreId); return(View(game)); }
public async Task <IActionResult> Edit(int id, [Bind("GenreId,Name,Description")] Genre genre) { if (id != genre.GenreId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(genre); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GenreExists(genre.GenreId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(genre)); }
public async Task <IActionResult> Edit(int id, [Bind("DeveloperId,Name,StreetAddress,City,Telephone")] Developer developer) { if (id != developer.DeveloperId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(developer); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DeveloperExists(developer.DeveloperId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(developer)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Tite,ReleaseDate,Price,Description,InStockAmount")] Game game) { if (id != game.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(game); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GameExists(game.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(game)); }
public IActionResult AddToCart(int id) { String userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var gameStoreUser = _context.Users.Include(user => user.Cart).Include(user => user.Cart.CartItems) .Where(x => x.Id == userId).SingleOrDefault(); if (gameStoreUser.Cart == null) { gameStoreUser.Cart = new Cart() { CartItems = new List <CartItem>() }; _context.Carts.Add(gameStoreUser.Cart); _context.Update(gameStoreUser); _context.SaveChanges(); _context.Update(gameStoreUser); } List <CartItem> items = gameStoreUser.Cart.CartItems; if (items.Exists(x => x.GameId == id)) { items.Where(x => x.GameId == id).SingleOrDefault().Qty++; } else { CartItem ci = new CartItem() { GameId = id, CartId = gameStoreUser.Cart.Id, Qty = 1 }; //_context.Add(ci); items.Add(ci); } _context.Update(gameStoreUser.Cart); _context.SaveChanges(); return(PartialView()); }