Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("idDpto,dsDpto")] Departamento departamento)
        {
            if (id != departamento.idDpto)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(departamento);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DepartamentoExists(departamento.idDpto))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(departamento));
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(int id, [Bind("idServico,dsServico")] Servico servico)
        {
            if (id != servico.idServico)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(servico);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ServicoExists(servico.idServico))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(servico));
        }
        public void Update(Usuario usuario)
        {
            bool existe = _context.Usuario.Any(x => x.idUsuario == usuario.idUsuario);

            if (!existe)
            {
                throw new NotFoundException("Id não encontrado!");
            }
            try
            {
                usuario.situacaoUsuario = ("Ativo");
                _context.Update(usuario);
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException e)
            {
                throw new DbConcurrencyException(e.Message);
            }
        }