コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("IDCategoria,Descricao")] TBCategoria tBCategoria)
        {
            if (id != tBCategoria.IDCategoria)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tBCategoria);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TBCategoriaExists(tBCategoria.IDCategoria))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tBCategoria));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("IDCategoria,Descricao")] TBCategoria tBCategoria)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tBCategoria);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tBCategoria));
        }