public async Task <ActionResult> delete(int CursoId)
        {
            try {
                var curso = await _context.Curso.FindAsync(CursoId);

                if (curso == null)
                {
                    return(NotFound());
                }
                _context.Remove(curso);
                await _context.SaveChangesAsync();

                return(NoContent());
            }
            catch {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Falha no acesso ao banco de dados."));
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult> delete(int AlunoId)
        {
            try{
                //verifica se existe aluno a ser excluído
                var aluno = await _context.Aluno.FindAsync(AlunoId);

                if (aluno == null)
                {
                    //método do EF
                    return(NotFound());
                }
                _context.Remove(aluno);
                await _context.SaveChangesAsync();

                return(NoContent());
            }
            catch {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Falha no acesso ao banco de dados."));
            }
            // retorna BadRequest se não conseguiu deletar
            return(BadRequest());
        }
        public async Task <ActionResult> delete(int AlunoId)
        {
            try
            {
                var aluno = await _context.Aluno.FindAsync(AlunoId);

                if (aluno == null)
                {
                    return(NotFound());
                }
                _context.Remove(aluno);
                await _context.SaveChangesAsync();

                return(NoContent());
            }
            catch
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Falha no acesso ao banco de dados."));
            }

            //return BadRequest();
        }
 public void Delete(TEntity entity) => _dbContext.Remove(entity);