private async Task <RelatorioSemestralPAPAluno> NovoRelatorioSemestralAluno(long relatorioSemestralId, string alunoCodigo, Turma turma, int semestre, RelatorioSemestralAlunoPersistenciaDto relatorioSemestralAlunoDto) { var relatorioSemestral = relatorioSemestralId > 0 ? await consultasRelatorioSemestral.ObterPorIdAsync(relatorioSemestralId) : NovoRelatorioSemestral(turma, semestre); var novoRelatorioAluno = new RelatorioSemestralPAPAluno() { AlunoCodigo = alunoCodigo, RelatorioSemestralTurmaPAP = relatorioSemestral, }; foreach (var secaoRelatorio in relatorioSemestralAlunoDto.Secoes) { novoRelatorioAluno.Secoes.Add(new RelatorioSemestralPAPAlunoSecao() { RelatorioSemestralPAPAluno = novoRelatorioAluno, SecaoRelatorioSemestralPAPId = secaoRelatorio.Id, }); } return(novoRelatorioAluno); }
public async Task <AuditoriaRelatorioSemestralAlunoDto> Salvar(string alunoCodigo, string turmaCodigo, int semestre, RelatorioSemestralAlunoPersistenciaDto relatorioSemestralAlunoDto) { var turma = await ObterTurma(turmaCodigo); await ValidarPersistenciaTurmaSemestre(turma, semestre); var relatorioSemestralAluno = relatorioSemestralAlunoDto.RelatorioSemestralAlunoId > 0 ? await repositorioRelatorioSemestralAluno.ObterCompletoPorIdAsync(relatorioSemestralAlunoDto.RelatorioSemestralAlunoId) : await NovoRelatorioSemestralAluno(relatorioSemestralAlunoDto.RelatorioSemestralId, alunoCodigo, turma, semestre, relatorioSemestralAlunoDto); using (var transacao = unitOfWork.IniciarTransacao()) { try { // Relatorio Semestral if (relatorioSemestralAluno.RelatorioSemestralTurmaPAP != null) { await comandosRelatorioSemestral.SalvarAsync(relatorioSemestralAluno.RelatorioSemestralTurmaPAP); relatorioSemestralAluno.RelatorioSemestralTurmaPAPId = relatorioSemestralAluno.RelatorioSemestralTurmaPAP.Id; } // Relatorio Semestral Aluno await repositorioRelatorioSemestralAluno.SalvarAsync(relatorioSemestralAluno); foreach (var secaoRelatorio in relatorioSemestralAlunoDto.Secoes) { var secaoRelatorioAluno = relatorioSemestralAluno.Secoes.FirstOrDefault(c => c.SecaoRelatorioSemestralPAPId == secaoRelatorio.Id); if (secaoRelatorioAluno != null) { secaoRelatorioAluno.RelatorioSemestralPAPAlunoId = relatorioSemestralAluno.Id; secaoRelatorioAluno.Valor = secaoRelatorio.Valor; if (!string.IsNullOrEmpty(secaoRelatorioAluno.Valor)) { // Relatorio Semestral Aluno x Secao await comandosRelatorioSemestralAlunoSecao.SalvarAsync(secaoRelatorioAluno); } else { await comandosRelatorioSemestralAlunoSecao.RemoverAsync(secaoRelatorioAluno); } } else if (!string.IsNullOrEmpty(secaoRelatorio.Valor)) { secaoRelatorioAluno = new RelatorioSemestralPAPAlunoSecao() { RelatorioSemestralPAPAlunoId = relatorioSemestralAlunoDto.RelatorioSemestralAlunoId, SecaoRelatorioSemestralPAPId = secaoRelatorio.Id, Valor = secaoRelatorio.Valor }; await comandosRelatorioSemestralAlunoSecao.SalvarAsync(secaoRelatorioAluno); } } unitOfWork.PersistirTransacao(); } catch (Exception) { unitOfWork.Rollback(); throw; } } return(MapearParaAuditorio(relatorioSemestralAluno)); }
//[Permissao(Permissao.NC_C, Permissao.NC_I, Policy = "Bearer")] public async Task <IActionResult> SalvarRelatorioAluno(string alunoCodigo, string turmaCodigo, int semestre , [FromBody] RelatorioSemestralAlunoPersistenciaDto relatorioSemestralAlunoDto , [FromServices] IComandosRelatorioSemestralPAPAluno comandosRelatorioSemestralAluno) => Ok(await comandosRelatorioSemestralAluno.Salvar(alunoCodigo, turmaCodigo, semestre, relatorioSemestralAlunoDto));