public IActionResult Delete([FromRoute] int?id) { if (id == null) { return(NotFound()); } _context.Delete(id); return(Ok()); }
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); } }
public void Delete(long id) { try { if (!ExistsAlunosComTurmas(id)) { _repository.Delete(id); } } catch (Exception ex) { throw ex; } }
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 }.")); } }
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()); }
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); }
public async Task <Turma> Apaga(int id) { var turma = await _repo.Delete(id); return(turma); }