public async Task <IActionResult> Edit(int id, [Bind("Id,Nome")] CategoriaLivro categoriaLivro) { if (id != categoriaLivro.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(categoriaLivro); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoriaLivroExists(categoriaLivro.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(categoriaLivro)); }
private static void AddLivro() { Console.WriteLine("Digite o Numero da Estante do Livro"); int NumeroEst = Convert.ToInt32(Console.ReadLine()); Estante Est = new Estante(); Est.Numero = NumeroEst; Biblioteca.Estantes.Add(Est); Console.WriteLine("Digite o Numero da Pratileira do Livro"); int NumeroPrat = Convert.ToInt32(Console.ReadLine()); Prateleira Prat = new Prateleira(); Prat.Numero = NumeroPrat; Est.Prateleiras.Add(Prat); Console.WriteLine("Digite o Nome do Livro"); Livro Book = new Livro(); Book.Titulo = Console.ReadLine(); Console.WriteLine("Digite a Categoria do Livro"); CategoriaLivro Cat = new CategoriaLivro(); Cat.Nome = Console.ReadLine(); Book.Categoria = Cat; Console.WriteLine("Digite o Autor do Livro"); AutorLivro Aut = new AutorLivro(); Aut.Nome = Console.ReadLine(); Book.Autor = Aut; Prat.Livros.Add(Book); }
public ActionResult Details(int id) { //Busco a categoria que tem o id igual ao parâmetro passado CategoriaLivro categoriaLivro = db.CategoriaLivroes.Find(id); //Retorno uma View com essa categoria return(View(categoriaLivro)); }
//Get, recebe o Id do item que será editado public ActionResult Edit(int id) { //Busco a categoria que tem o Id passado por parâmetro CategoriaLivro categoriaLivro = db.CategoriaLivroes.Find(id); //E retorno uma View com ela return(View(categoriaLivro)); }
//Confirma que a Categoria cujo Id seja igual o passado por parâmetro vai ser deletada public ActionResult DeleteConfirmed(int id) { CategoriaLivro categoriaLivro = db.CategoriaLivroes.Find(id); db.CategoriaLivroes.Remove(categoriaLivro); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create([Bind("Id,Nome")] CategoriaLivro categoriaLivro) { if (ModelState.IsValid) { _context.Add(categoriaLivro); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(categoriaLivro)); }
public void Excluir(CategoriaLivro categoria) { try { ldc.Categorias.DeleteOnSubmit(categoria); ldc.SubmitChanges(); } catch (Exception e) { throw new Exception(e.Message); } }
protected override void ToViewModel() { CategoriaLivro categoria = (CategoriaLivro)Entidades[typeof(CategoriaLivro).Name]; CategoriaLivroModel vm = new CategoriaLivroModel { Id = categoria.Id, Nome = categoria.Nome, Inativo = categoria.Inativo }; _viewModel = vm; }
public void Editar(CategoriaLivro categoriaNova) { try { CategoriaLivro categoriaVelha = getById(categoriaNova.Id); categoriaVelha.Nome = categoriaNova.Nome; ldc.SubmitChanges(); } catch (Exception e) { throw new Exception(e.Message); } }
protected override void ToEntidade() { CategoriaLivroModel vm = (CategoriaLivroModel)ViewModel; CategoriaLivro ctg = new CategoriaLivro { Nome = vm.Nome, Id = vm.Id }; _entidades = new Dictionary <string, object> { [typeof(CategoriaLivro).Name] = ctg }; }
public IActionResult _InativarReativarCategoriaPartial(int id) { CategoriaLivro ctg = _facade.GetEntidade(new CategoriaLivro { Id = id }); _vh = new CategoriaLivroViewHelper { Entidades = new Dictionary <string, object> { [typeof(CategoriaLivro).Name] = ctg } }; return(PartialView("../Admin/PartialViews/_InativarReativarCategoriaPartial", _vh.ViewModel)); }
//Assim como o Create, vai receber a categoria que foi editada na View do método acima public ActionResult Edit(CategoriaLivro categoriaLivro) { if (ModelState.IsValid) { db.Entry(categoriaLivro).State = EntityState.Modified; db.SaveChanges(); //Se o model é válido, retorno para a View de Index return(RedirectToAction("Index")); } else { //Caso o model seja inválido, vai retornar para a View de Edit return(View(categoriaLivro)); } }
public IActionResult AdicionarCategoria(CategoriaLivroModel categoria) { _vh = new CategoriaLivroViewHelper { ViewModel = categoria }; CategoriaLivro ctgNova = (CategoriaLivro)_vh.Entidades[typeof(CategoriaLivro).Name]; string msg = _facade.Cadastrar(ctgNova); if (!String.IsNullOrEmpty(msg)) { TempData["Alert"] = msg; } return(RedirectToAction(nameof(ConfigLoja))); }
public IActionResult InativarReativarCategoria(int id) { CategoriaLivro ctgDb = _facade.GetEntidade(new CategoriaLivro { Id = id }); ctgDb.Inativo = !ctgDb.Inativo; string msg = _facade.Editar(ctgDb); if (!String.IsNullOrEmpty(msg)) { TempData["Alert"] = msg; } return(RedirectToAction(nameof(ConfigLoja))); }
public IActionResult _EditarCategoriaPartial(int id) { ViewBag.Operacao = "edit"; CategoriaLivro ctg = _facade.GetEntidade(new CategoriaLivro { Id = id }); _vh = new CategoriaLivroViewHelper { Entidades = new Dictionary <string, object> { [typeof(CategoriaLivro).Name] = ctg } }; return(PartialView("../Admin/PartialViews/_ConfigCategoriaPartial", _vh.ViewModel)); }
//Por definição, uma página chamada Create vai postar para uma Url Create //Então, o método acima (Create()) sem parâmetros apenas retorna a View //Enquanto esse método aqui (Create(CategoriaLivro categoriaLivro)) que recebe uma categoriaLivro //Será o retorno da View Create para o controller //Ou seja, a página de Create vai postar de volta para Create public ActionResult Create(CategoriaLivro categoriaLivro) { //ModelState.IsValid vai validar se o model passado por parâmetro //cumpre com todas as definições das Annotations, por exemplo [StringLength(20)] if (ModelState.IsValid) { //Se o model é válido, adiciona no banco db.CategoriaLivroes.Add(categoriaLivro); //Salva db.SaveChanges(); //E retorna para a View de Index return(RedirectToAction("Index")); } else { //Se o model não for válido, vai voltar para a View de Create, para que o usuário corrija return(View(categoriaLivro)); } }
protected void btExcluir_click(object sender, EventArgs e) { CategoriaLivroDAO catDAO = new CategoriaLivroDAO(); LivroDAO livDAO = new LivroDAO(); String id = idEditar.Value; if (id != "-1") { CategoriaLivro cat = catDAO.getById(Int32.Parse(id)); foreach (Livro l in cat.Livros) { livDAO.Excluir(l); } catDAO.Excluir(catDAO.getById(Int32.Parse(id))); Response.Redirect("GerenciarCategorias.aspx", true); } }
//Retorna a página de confirmação de deleção public ActionResult Delete(int id) { CategoriaLivro categoriaLivro = db.CategoriaLivroes.Find(id); return(View(categoriaLivro)); }