public async Task <IActionResult> Edit(int id, [Bind("IdEditora,Nome")] Editora editora) { if (id != editora.IdEditora) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(editora); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EditoraExists(editora.IdEditora)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(editora)); }
public async Task <IActionResult> Edit(int id, [Bind("IdLivro,Codigo,Nome,Autor,Editora")] Livro livro) { if (id != livro.IdLivro) { return(NotFound()); } if (ModelState.IsValid) { if ((_context.Livro.Where(x => x.Codigo == livro.Codigo && livro.IdLivro != x.IdLivro).Count() > 0) || (_context.Livro.Where(x => x.Nome == livro.Nome && livro.IdLivro != x.IdLivro).Count() > 0)) { ViewBag.Message = "*Já existe um livro cadastrado com esses dados"; } else { try { _context.Update(livro); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LivroExists(livro.IdLivro)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } } ViewData["Autor"] = new SelectList(_context.Autor, "IdAutor", "Nome", livro.Autor); ViewData["Editora"] = new SelectList(_context.Editora, "IdEditora", "Nome", livro.Editora); return(View(livro)); }
public async Task <IActionResult> Edit(int id, [Bind("IdAutor,Nome")] Autor autor) { if (id != autor.IdAutor) { return(NotFound()); } if (ModelState.IsValid) { if (_context.Autor.Where(x => x.Nome == autor.Nome && autor.IdAutor != x.IdAutor).Count() > 0) { ViewBag.Message = "*Já existe um autor(a) cadastrado com esses dados"; } else { try { _context.Update(autor); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AutorExists(autor.IdAutor)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } } return(View(autor)); }