Exemple #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Codigo,Nome,ZFM,EstadoId")] Municipio municipio)
        {
            if (id != municipio.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(municipio);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MunicipioExists(municipio.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EstadoId"] = new SelectList(_context.Estado, "Id", "Nome", municipio.EstadoId);
            return(View(municipio));
        }
Exemple #2
0
        public async Task UpdateAsync(Pais obj)
        {
            bool hasAny = await _context.Pais.AnyAsync(x => x.Id == obj.Id);

            if (!hasAny)
            {
                throw new NotFoundException("Id não encontrado");
            }
            try
            {
                _context.Update(obj);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException e)
            {
                throw new DbConcurrencyException(e.Message);
            }
        }