Example #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));
        }
Example #2
0
 //verifica se os ids sao iguais, caso nao seja ele para!. Se os Ids forem iguais entao salva.
 public void Update(Carro obj)
 {
     if (!_context.Carro.Any(x => x.ID == obj.ID))
     {
         throw new DllNotFoundException("Id não encontrado. :(");
     }
     try
     {
         _context.Update(obj);
         _context.SaveChanges();
     }
     catch (DbUpdateConcurrencyException ex)
     {
         throw new DbUpdateConcurrencyException(ex.Message);
     }
 }