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

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tipoContato);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TipoContatoExists(tipoContato.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tipoContato));
        }
コード例 #2
0
        public async Task Update(Contatos contatos)
        {
            if (!await _context.Contatos.AnyAsync(x => x.Id == contatos.Id))
            {
                throw new NotFoundException("Id not found");
            }

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