public async Task <IActionResult> Edit(int id, [Bind("Id,Nome,Simbolo,Cadastro")] Criptomoeda criptomoeda) { if (id != criptomoeda.Id) { return(RedirectToAction(nameof(Error), new { message = "Id não encontrado!" })); } if (ModelState.IsValid) { try { _context.Update(criptomoeda); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CriptomoedaExists(criptomoeda.Id)) { return(RedirectToAction(nameof(Error), new { message = "Criptomoeda não encontrada!" })); } else { return(RedirectToAction(nameof(Error), new { message = "" })); } } return(RedirectToAction(nameof(Index))); } return(View(criptomoeda)); }
public async Task <IActionResult> Create([Bind("Id,Nome,Simbolo,Cadastro")] Criptomoeda criptomoeda) { if (_context.Criptomoeda.Any(c => c.Nome == criptomoeda.Nome)) { return(RedirectToAction(nameof(Error), new { message = "Criptomoeda já cadastrada!" })); } if (_context.Criptomoeda.Any(c => c.Simbolo == criptomoeda.Simbolo)) { return(RedirectToAction(nameof(Error), new { message = "Criptomoeda já cadastrada!" })); } if (ModelState.IsValid) { _context.Add(criptomoeda); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(criptomoeda)); }