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(); }
public void SelecionaPagamentos() { if (LojaSelecionada != null) { Pagamentos = new ObservableCollection <Pagamento>(PagamentosDb.FindAll().ToList()); Pagamentos = new ObservableCollection <Pagamento>(Pagamentos.Where(x => x.LojaId == LojaSelecionada.Id && x.DataVencimento.Month == DataSelecionada.Month && x.DataVencimento.Year == DataSelecionada.Year).ToList()); foreach (var item in Pagamentos) { item.LojaNome = LojaSelecionada.Nome; item.MembroNome = MembrosDb.FindById(item.MembroId).Nome; } } else { return; } foreach (var membro in MembrosDb.Find(x => x.Lojas.Exists(v => v == LojaSelecionada.Id)).ToList()) { if (Pagamentos.Where(x => x.MembroId == membro.Id && x.LojaId == LojaSelecionada.Id && x.DataVencimento.Month == DataSelecionada.Month && x.DataVencimento.Year == DataSelecionada.Year).Count() == 0) { var pagamento = new Pagamento() { MembroId = membro.Id, DataVencimento = new DateTime(DataSelecionada.Year, DataSelecionada.Month, 10), LojaId = LojaSelecionada.Id, StatusPagamento = StatusPagamento.Irregular, LojaNome = LojaSelecionada.Nome, MembroNome = membro.Nome }; PagamentosDb.Insert(pagamento); Pagamentos.Add(pagamento); } } }