コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("PessoaId,Nome,Foto")] Pessoa pessoa)
        {
            if (id != pessoa.PessoaId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(pessoa);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PessoaExists(pessoa.PessoaId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(pessoa));
        }
コード例 #2
0
        public Pessoa Update(int Id, Pessoa Pessoa)
        {
            IQueryable <Pessoa> result = _dbContext.Pessoas.Where(p => p.Id == Id);

            if (result.Count() > 0)
            {
                Pessoa pessoaFromDatabase = result.First();
                pessoaFromDatabase.Nome = Pessoa.Nome;
                _dbContext.Update(pessoaFromDatabase);
                _dbContext.SaveChanges();
                return(pessoaFromDatabase);
            }

            return(null);
        }