Example #1
0
        public async Task <IActionResult> Edit(int id, [Bind("ProdutoID,Nome,ValorUnitario")] Produto produto)
        {
            if (id != produto.ProdutoID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(produto);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProdutoExists(produto.ProdutoID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(produto));
        }
Example #2
0
        public void Update(Cliente obj)
        {
            if (!_context.Cliente.Any(x => x.ClienteID == obj.ClienteID))
            {
                throw new NotFoundException("Id não encontrado");
            }

            try
            {
                _context.Update(obj);
                _context.SaveChanges();
            }
            catch (DbConcurrencyException e)
            {
                throw new DbConcurrencyException(e.Message);
            }
        }