public async Task <IActionResult> PutTbCategoria(int id, TbCategoria tbCategoria) { if (id != tbCategoria.CodCategoria) { return(BadRequest()); } _context.Entry(tbCategoria).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TbCategoriaExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("Id,Nome")] TbCategoria tbCategoria) { if (CategoriaExiste(tbCategoria.Nome) == false) { if (ModelState.IsValid) { _context.Add(tbCategoria); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } else { ModelState.AddModelError("Nome", "Categoria Já Existe!"); } return(View(tbCategoria)); }
public async Task <ActionResult <TbCategoria> > PostTbCategoria(TbCategoria tbCategoria) { _context.TbCategoria.Add(tbCategoria); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (TbCategoriaExists(tbCategoria.CodCategoria)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetTbCategoria", new { id = tbCategoria.CodCategoria }, tbCategoria)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Nome")] TbCategoria tbCategoria) { if (id != tbCategoria.Id) { return(NotFound()); } if (CategoriaExiste(tbCategoria.Nome, tbCategoria.Id) == false) { if (ModelState.IsValid) { try { _context.Update(tbCategoria); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TbCategoriaExists(tbCategoria.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } } else { ModelState.AddModelError("Nome", "Categoria Já Existe!"); } return(View(tbCategoria)); }