public async Task <IActionResult> EditCard([FromForm] CardEditVM card) { if (!ModelState.IsValid) { return(RedirectToAction(nameof(CardController.ListCard), "Card", new { cardsId = card.CardsId.ToString(), cardsName = "" })); } else { Card card_bd = await _cardService.GetCardByIdWithItem(card.Id); if (card_bd == null) { return(RedirectToAction(nameof(CardController.ListCard), "Card", new { cardsId = card.CardsId.ToString(), cardsName = "" })); } card_bd.Item.Back = card.Item.Back; card_bd.Item.Face = card.Item.Face; bool good = await _crudCardService.UpdateAsync(card_bd); if (good) { return(RedirectToAction(nameof(CardController.ListCard), "Card", new { cardsId = card.CardsId.ToString(), cardsName = "" })); } } return(RedirectToAction(nameof(HomeController.Error), "Home")); }
public async Task <IActionResult> EditCard(int id, int cardsId) { if (id < 0) { return(RedirectToAction(nameof(CardController.ListCard), "Card", new { cardsId = cardsId.ToString(), cardsName = "" })); } else { Card card = await _cardService.GetCardByIdWithItem(id); if (card == null) { return(RedirectToAction(nameof(CardController.ListCard), "Card", new { cardsId = cardsId.ToString(), cardsName = "" })); } CardEditVM cvm = new CardEditVM { Id = card.Id, CardsId = card.CardsId, UserScore = card.UserScore, Efactor = card.Efactor, Item = new ItemVM { Back = card.Item.Back, Face = card.Item.Face } }; return(View(cvm)); } }