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

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(departamentos);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DepartamentosExists(departamentos.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(departamentos));
        }
コード例 #2
0
        public async Task UpdateAsync(Vendedor obj)
        {
            bool temAlgum = await _context.Vendedor.AnyAsync(x => x.Id == obj.Id);

            if (!temAlgum)
            {
                throw new DllNotFoundException("Id não encontrado!");
            }

            try
            {
                _context.Update(obj);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException e)
            {
                throw new DBConcurrencyException(e.Message);
            }
        }