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

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(department);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DepartmentExists(department.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(department));
        }
コード例 #2
0
 public void Update(Seller obj)
 {
     // Verifica se há algum vendedor no banco com esse Id
     if (_context.Seller.Any(s => s.Id == obj.Id))
     {
         // Atualiza o registro do vendedor na tabela Seller
         _context.Update(obj);
         _context.SaveChanges();
     }
 }
コード例 #3
0
        public void Update(Seller obj)
        {
            /*Verifica se há algum vendedor no banco com esse Id*/
            if (_context.Seller.Any(s => s.Id == obj.Id))
            {
                try
                {
                    /*Atualiza o registro do vendedor na tabela Seller */
                    _context.Update(obj);
                    _context.SaveChanges();
                }

                /*Esse erro é do entity framework, ou seja,
                 * da camada de acesso aos dados*/
                catch (DbUpdateConcurrencyException e)
                {
                    throw new DbConcurrencyException(e.Message);
                }
            }
            else
            {
                throw new NotFoundException("ID not found");
            }
        }