//Get Deck/EditDeck public ActionResult UpdateDeck(int deckId) { DeckItem oldDeck = _db.GetDeck(deckId); UpdateDeckViewModel model = new UpdateDeckViewModel { DeckId = deckId, Name = oldDeck.Name, Description = oldDeck.Description }; return(View("UpdateDeck", model)); }
public ActionResult UpdateDeck(UpdateDeckViewModel model) { ActionResult result; bool updateDeckSuccess = true; //Validate the model before proceeding if (!ModelState.IsValid) { result = View("ViewDecks"); } else { //make deckitem int userId = GetActiveUserId(); DeckItem deck = new DeckItem { Id = model.DeckId, Name = model.Name, Description = model.Description, UserID = userId }; //Attempt add to database updateDeckSuccess = _db.UpdateDeck(deck, deck.Id); //send success/error message if (updateDeckSuccess) { TempData["UpdateSuccess"] = $"{deck.Name} deck edit successful"; } else { TempData["ErrorMessage"] = $"DATABASE ERROR: {deck.Name} deck edit failed"; } result = RedirectToAction("ViewDecks"); } return(result); }