public async Task <string[]> SalvarAsync(FechamentoFinalSalvarDto fechamentoFinalSalvarDto) { var turma = await ObterTurma(fechamentoFinalSalvarDto.TurmaCodigo); var dataAtual = DateTime.Today; var existePeriodoAberturaOuReabertura = await mediator.Send(new TurmaEmPeriodoAbertoQuery(turma, dataAtual, 0, dataAtual.Year == turma.AnoLetivo)); var fechamentoTurmaDisciplina = await TransformarDtoSalvarEmEntidade(fechamentoFinalSalvarDto, turma); var mensagensDeErro = await servicoFechamentoFinal.SalvarAsync(fechamentoTurmaDisciplina, turma); return(mensagensDeErro.ToArray()); }
public async Task <IActionResult> Salvar([FromBody] FechamentoFinalSalvarDto fechamentoFinalSalvarDto, [FromServices] IComandosFechamentoFinal comandosFechamentoFinal) { var mensagens = await comandosFechamentoFinal.SalvarAsync(fechamentoFinalSalvarDto); if (mensagens != null && mensagens.Any()) { return(StatusCode(601, new RetornoBaseDto() { Mensagens = mensagens.ToList() })); } return(Ok()); }
private async Task <FechamentoTurmaDisciplina> TransformarDtoSalvarEmEntidade(FechamentoFinalSalvarDto fechamentoFinalSalvarDto, Turma turma) { var disciplinaId = fechamentoFinalSalvarDto.EhRegencia ? long.Parse(fechamentoFinalSalvarDto.DisciplinaId) : fechamentoFinalSalvarDto.Itens.First().ComponenteCurricularCodigo; FechamentoTurmaDisciplina fechamentoTurmaDisciplina = null; var fechamentoFinalTurma = await repositorioFechamentoTurma.ObterPorTurmaPeriodo(turma.Id); if (fechamentoFinalTurma == null) { fechamentoFinalTurma = new FechamentoTurma(0, turma.Id); } else { fechamentoTurmaDisciplina = await repositorioFechamentoTurmaDisciplina.ObterFechamentoTurmaDisciplina(fechamentoFinalSalvarDto.TurmaCodigo, disciplinaId); } if (fechamentoTurmaDisciplina == null) { fechamentoTurmaDisciplina = new FechamentoTurmaDisciplina() { DisciplinaId = disciplinaId, Situacao = SituacaoFechamento.ProcessadoComSucesso } } ; fechamentoTurmaDisciplina.FechamentoTurma = fechamentoFinalTurma; foreach (var agrupamentoAluno in fechamentoFinalSalvarDto.Itens.GroupBy(a => a.AlunoRf)) { var fechamentoAluno = await repositorioFechamentoAluno.ObterFechamentoAlunoENotas(fechamentoTurmaDisciplina.Id, agrupamentoAluno.Key); if (fechamentoAluno == null) { fechamentoAluno = new FechamentoAluno() { AlunoCodigo = agrupamentoAluno.Key } } ; foreach (var fechamentoItemDto in agrupamentoAluno) { var fechamentoNota = fechamentoAluno.FechamentoNotas.FirstOrDefault(c => c.DisciplinaId == fechamentoItemDto.ComponenteCurricularCodigo); if (fechamentoNota != null) { if (fechamentoItemDto.Nota.HasValue) { if (fechamentoNota.Nota.Value != fechamentoItemDto.Nota.Value) { await mediator.Send(new SalvarHistoricoNotaFechamentoCommand(fechamentoNota.Nota.Value, fechamentoItemDto.Nota.Value, fechamentoNota.Id)); } } else if (fechamentoNota.ConceitoId.Value != fechamentoItemDto.ConceitoId.Value) { await mediator.Send(new SalvarHistoricoConceitoFechamentoCommand(fechamentoNota.ConceitoId.Value, fechamentoItemDto.ConceitoId.Value, fechamentoNota.Id)); } } MapearParaEntidade(fechamentoNota, fechamentoItemDto, fechamentoAluno); } fechamentoTurmaDisciplina.FechamentoAlunos.Add(fechamentoAluno); } return(fechamentoTurmaDisciplina); }