public async Task <IActionResult> Get(int IDTurmaAluno, int IDTurma, int IDAluno) { var responseContent = new ResponseContent(); try { if ((IDTurmaAluno.ToString() != null) && (IDTurmaAluno > 0)) { responseContent.Object = await _turmaAlunoBLL.GetTurmaAlunoAsync(IDTurmaAluno); } else if ((IDTurma > 0) && (IDAluno > 0)) { responseContent.Object = await _turmaAlunoBLL.GetTurmaAlunoAsync(IDAluno, IDTurma); } else { responseContent.Message = "A pesquisa não retornou dados"; return(NotFound(responseContent)); } if (responseContent.Object == null) { responseContent.Message = "A pesquisa não retornou dados"; return(NotFound(responseContent)); } responseContent.Message = "Operação realizada com sucesso!!"; return(Ok(responseContent)); } catch (BusinessException bex) { responseContent.Message = bex.Message; return(BadRequest(responseContent)); } catch (Exception ex) { responseContent.Message = ex.Message; return(BadRequest(responseContent)); } }
public async Task InsertVotoDiarioAsync(Voto voto)/// idAluno, idTurma,idRestaurante { var msg = ""; var turmaAluno = await _turmaAlunoBLL.GetTurmaAlunoAsync(voto.idAluno, voto.idTurma); //pega idTurmaAluno var ultimoPeriodoTurma = await _periodoBLL.GetUltimoPeriodoAsync(voto.idTurma); // pega idPeriodo if (await _periodoBLL.IsPeriodoAbertoAsync(ultimoPeriodoTurma.IDPeriodo)) //valida se período está aberto { await _periodoDiarioBLL.AbrirPeriodoDiario(ultimoPeriodoTurma.IDPeriodo); //idTurmaAluno idPeriodoResultado (id rest + id_periodo) // pegar o periodo resultado var periodoResultado = await _periodoResultadoBLL.GetPeriodo(0, voto.idRestaurante, ultimoPeriodoTurma.IDPeriodo); if (periodoResultado != null) { // pegar ultimo periodo diario e validar se está aberto var periodoDiario = await _periodoDiarioBLL.GetUltimoPeriodoDiarioAsync(periodoResultado.IDPeriodo); if (await _periodoDiarioBLL.IsPeriodoAbertoAsync(periodoDiario.IDPeriodoDiario)) { // validar se aluno (idTurmaAluno) já existe na tabela de voto diário if (await this.IsAlunoJaVotouAsync(periodoDiario.IDPeriodoDiario, turmaAluno.IDTurmaAluno)) { msg = "Aluno já votou!"; throw new Exception(msg); } else { var data = DateTime.Now; var votoDiario = new VotoDiario(id: 0, periodoResultado.IDPeriodoResultado, turmaAluno.IDTurmaAluno, data, periodoDiario.IDPeriodoDiario); _votoDiarioRepository.InsertVotoDiarioAsync(votoDiario); await _votoDiarioRepository.UnitOfWork.Commit(); } } else { msg = "Não existe período aberto para votação"; throw new Exception(msg); } } else { msg = "Restaurante informado não pertence a esse período/turma"; throw new Exception(msg); } } else { msg = "Período de votação semanal já encerrado"; throw new Exception(msg); } }