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

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(departamento);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DepartamentoExists(departamento.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(departamento));
        }
コード例 #2
0
 public void Update(Vendedor obj)
 {
     if (!_context.Vendedor.Any(x => x.Id == obj.Id))
     {
         throw new NotFoundException("Vendedor não Encontrado");
     }
     try
     {
         _context.Update(obj);
         _context.SaveChanges();
     }
     catch (DbUpdateConcurrencyException e)
     {
         throw new DbConcurrencyException(e.Message);
     }
 }