public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } InventoryItem inventoryItem = await _db.InventoryItems.FirstOrDefaultAsync(i => i.ID == id); if (inventoryItem == null) { return(NotFound()); } IEnumerable <BoardGame> boardGames = await _db.BoardGames .OrderBy(b => b.Title) .ToListAsync(); InventoryItemDetailsViewModel inventoryItemDetailsViewModel = new InventoryItemDetailsViewModel() { InventoryItem = inventoryItem, BoardGame = boardGames }; return(View(inventoryItemDetailsViewModel)); }
public async Task <IActionResult> Create() { InventoryItem inventoryItem = new InventoryItem() { ReceivedDate = DateTime.UtcNow.Date }; IEnumerable <BoardGame> boardGames = await _db.BoardGames .OrderBy(b => b.Title) .ToListAsync(); InventoryItemDetailsViewModel inventoryItemDetailsViewModel = new InventoryItemDetailsViewModel() { InventoryItem = inventoryItem, BoardGame = boardGames }; return(View(inventoryItemDetailsViewModel)); }
public async Task <IActionResult> Edit(int id, [Bind("ID", "InStock", "ReceivedDate", "BoardGameID")] InventoryItem inventoryItem) { var inventoryItemToUpdate = await _db.InventoryItems.FindAsync(id); if (inventoryItemToUpdate == null) { return(NotFound()); } if (ModelState.IsValid) { if (await TryUpdateModelAsync <InventoryItem>( inventoryItemToUpdate, "inventoryitem", i => i.InStock, i => i.ReceivedDate, i => i.BoardGameID)) { await _db.SaveChangesAsync(); return(RedirectToAction("Index")); } } IEnumerable <BoardGame> boardGames = await _db.BoardGames .OrderBy(b => b.Title) .ToListAsync(); InventoryItemDetailsViewModel inventoryItemDetailsViewModel = new InventoryItemDetailsViewModel() { InventoryItem = inventoryItem, BoardGame = boardGames }; return(View(inventoryItemDetailsViewModel)); }