Exemplo n.º 1
0
        public IActionResult Delete([FromRoute] int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            _context.Delete(id);

            return(Ok());
        }
Exemplo n.º 2
0
        public void Delete(int id)
        {
            try
            {
                _turmaRepository.Delete(id);

                _unitOfWork.Commit();
            }
            catch (DbUpdateException te)
            {
                _unitOfWork.Rollback();
                throw new ApplicationException(Resource.EXCEPTION_TURMA_COM_ALUNOS_RELACIONADOS);
            }
        }
Exemplo n.º 3
0
 public void Delete(long id)
 {
     try
     {
         if (!ExistsAlunosComTurmas(id))
         {
             _repository.Delete(id);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 4
0
        public async Task <ActionResult <Turma> > DeleteTurma(int id)
        {
            try
            {
                _turmaRepository.Delete(id);

                var turma = _turmaRepository.Get(id);
                if (turma == null)
                {
                    return(NotFound("Turma não encontrada."));
                }

                await _turmaRepository.SaveChangeAsync();

                return(Ok($"{turma.Descricao} deletada com sucesso."));
            }
            catch (Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Ops! Houve um erro: { ex.Message }."));
            }
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Delete(int id)
        {
            try
            {
                var curso = await _repo.GetTurmaById(id);

                if (curso == null)
                {
                    return(NotFound(MSG.NaoExisteTurma));
                }
                _repo.Delete(curso);
                if (await _repo.SaveChangesAsync())
                {
                    return(Ok(MSG.DeleteTurma));
                }
            }
            catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status501NotImplemented, MSG.BancoDadosFalhou));
            }
            return(BadRequest());
        }
Exemplo n.º 6
0
        public ActionResult DelTurma(long id)
        {
            var turma = ObterListaTurmas().Where(t => t.Id == id).FirstOrDefault();

            if (turma == null)
            {
                return(RedirectToAction("Unauthorized", "Erro"));
            }
            if (turma.Alunos.Count > 0)
            {
                return(new HttpStatusCodeResult(400));
                //Verificação a ser feita em caso de exclusão lógica (atualmente não implementada)
                //foreach (var aluno in turma.Alunos)
                //{
                //    if (aluno.Ativo == 1)
                //    {
                //        return new HttpStatusCodeResult(400);
                //    }
                //}
            }
            _turmaRepository.Delete(turma);
            return(null);
        }
Exemplo n.º 7
0
    public async Task <Turma> Apaga(int id)
    {
        var turma = await _repo.Delete(id);

        return(turma);
    }