Exemple #1
0
        public async Task RemoverDadosAlunoAsync(int alunoId)
        {
            var aluno = await Alunos.FindAsync(alunoId);

            // Apagar aulas assistidas
            var aulasAssistidas = await AulasAssistidas.Where(aa => aa.AlunoId == aluno.Id).ToListAsync();

            if (aulasAssistidas != null)
            {
                AulasAssistidas.RemoveRange(aulasAssistidas);
            }

            // Apagar anotacoes
            var anotacoes = await AnotacoesAulas.Where(aa => aa.AlunoId == aluno.Id).ToListAsync();

            if (anotacoes != null)
            {
                AnotacoesAulas.RemoveRange(anotacoes);
            }

            // Apagar notas
            var notas = await Notas.Where(n => n.AlunoId == aluno.Id).ToListAsync();

            if (notas != null)
            {
                Notas.RemoveRange(notas);
            }

            // Apagar matriculas
            var matriculas = await Matriculas.Where(m => m.AlunoId == aluno.Id).ToListAsync();

            if (matriculas != null)
            {
                // Apagar Status Aulas
                foreach (var matricula in matriculas)
                {
                    var statusAulas = StatusAulas.Where(sa => sa.MatriculaId == matricula.Id).SingleOrDefault();
                    if (statusAulas != null)
                    {
                        StatusAulas.Remove(statusAulas);
                    }

                    var pagamento = await Pagamentos.Where(p => p.Id == matricula.PagamentoId).SingleOrDefaultAsync();

                    Pagamentos.Remove(pagamento);
                    Matriculas.Remove(matricula);
                }
            }

            await SaveChangesAsync();
        }