public void RealizaChamada(ChamadaDTO registroPresenca) { var alunos = _alunoRepository.GetAllByTurmaId(registroPresenca.TurmaId); if (alunos == null || alunos.Any() == false) { throw new AlunoNaoEncontrado(String.Format(NENHUM_ALUNO_ENCOTRADO_PARA_TURMA, registroPresenca.AnoTurma)); } var aula = _aulaRepository.GetById(registroPresenca.AulaId); if (aula == null) { throw new AulaNaoEncontrada(String.Format(NENHUMA_AULA_ENCOTRADA_NESTA_DATA, registroPresenca.Data)); } foreach (var item in registroPresenca.Alunos) { var aluno = alunos.First(x => x.Id == item.AlunoId); aluno.RegistraPresenca(aula, item.Status); _alunoRepository.Update(aluno); } aula.ChamadaRealizada = true; _aulaRepository.Update(aula); _unitOfWork.Commit(); }
public ChamadaDTO GetChamadaByAula(AulaDTO aulaDTO) { var chamada = new ChamadaDTO(); Aula aula = _aulaRepository.GetById(aulaDTO.Id); chamada.ChamadaRealizada = aula.ChamadaRealizada; if (aula.ChamadaRealizada) { chamada.Alunos = aula.Presencas .Select(x => new ChamadaAlunoDTO (x.Aluno.Id, x.Aluno.Nome, x.StatusPresenca)).ToList(); } else { var alunos = _alunoRepository.GetAllByTurmaId(aulaDTO.TurmaId); chamada.Alunos = alunos .Select(x => new ChamadaAlunoDTO (x.Id, x.Nome, "C")).ToList(); } chamada.AulaId = aula.Id; chamada.AnoTurma = aula.Turma.Ano; return(chamada); }
public override void RealizaChamada() { AulaDTO aulaSelecionada = _control.GetAulaSelecionada(); if (aulaSelecionada == null) { MessageBox.Show("Nenhuma Aula selecionada. Selecionar uma Aula antes para realizar a chamada dos alunos"); return; } ChamadaDTO chamada = _aulaService.GetChamadaByAula(aulaSelecionada); ChamadaDialog dialog = new ChamadaDialog(); dialog.Chamada = chamada; dialog.Chamada.AulaId = aulaSelecionada.Id; dialog.Chamada.TurmaId = aulaSelecionada.TurmaId; if (dialog.ShowDialog() == DialogResult.OK) { _aulaService.RealizaChamada(chamada); } }
public IActionResult Get(int classe, DateTime data) { var retorno = new ChamadaDTO(); var chamada = UnidadeTrabalho.ChamadaRepositorio.ObterPorClasseEData(classe, data); if (chamada != null) { retorno.Biblias = chamada.Biblias; retorno.Revistas = chamada.Revistas; retorno.Visitantes = chamada.Visitantes; retorno.Oferta = chamada.Oferta; if (chamada.Presencas != null && chamada.Presencas.Any()) { retorno.Presencas = chamada.Presencas.Select(x => new AlunoDTO { Id = x.IdAluno, Nome = x.NomeAluno }); } } // Busca alunos matriculados var matriculas = UnidadeTrabalho.MatriculaRepositorio.Todos(x => x.ClasseId == classe && x.DataMatricula <= data.Date && (x.DataTerminoMatricula == null || x.DataTerminoMatricula > data.Date), include: x => x.Aluno); if (matriculas.Any()) { retorno.Matriculados = matriculas.Select(x => new AlunoDTO { Id = x.Aluno.Id, Nome = x.Aluno.Nome }); } return(Ok(retorno)); }
public IActionResult Post(int classe, DateTime data, [FromBody] ChamadaDTO chamadaDto) { var chamada = UnidadeTrabalho.ChamadaRepositorio.ObterPorClasseEData(classe, data); if (chamada == null) { chamada = new Chamada { ClasseId = classe, Data = data.Date }; UnidadeTrabalho.ChamadaRepositorio.Adicionar(chamada); UnidadeTrabalho.Salvar(); } return(TratarRetornoTransacao(unidadeTrabalho => { if (chamadaDto.Visitantes.HasValue && chamada.Visitantes != chamadaDto.Visitantes) { chamada.Visitantes = chamadaDto.Visitantes.Value; } if (chamadaDto.Biblias.HasValue && chamada.Biblias != chamadaDto.Biblias) { chamada.Biblias = chamadaDto.Biblias.Value; } if (chamadaDto.Revistas.HasValue && chamada.Revistas != chamadaDto.Revistas) { chamada.Revistas = chamadaDto.Revistas.Value; } if (chamadaDto.Oferta.HasValue && chamada.Oferta != chamadaDto.Oferta) { chamada.Oferta = chamadaDto.Oferta.Value; } if (chamadaDto.Presencas != null) { chamada.Presencas = new List <Presenca>(chamadaDto.Presencas.Select(x => new Presenca { IdAluno = x.Id, NomeAluno = x.Nome })); } unidadeTrabalho.ChamadaRepositorio.Alterar(chamada); })); }
public void RegistraPresenca_deveria_lancar_excecao_AlunoNaoEncontrado() { //arrange AlunoRepository .Setup(x => x.GetAllByTurmaId(It.IsAny <int>())) .Returns(null as List <Aluno>); var comando = new ChamadaDTO { AnoTurma = 2000 }; // act AulaService.RealizaChamada(comando); // assert is [ExpectedException] }
public void RegistraPresenca_deveria_lancar_excecao_AulaNaoEncontrado() { //arrange int qtdAlunos = 1; var alunos = ObjectBuilder.CriaListaAlunos(qtdAlunos); AlunoRepository .Setup(x => x.GetAllByTurmaId(It.IsAny <int>())) .Returns(alunos); AulaRepository .Setup(x => x.GetById(It.IsAny <int>())) .Returns(null as Aula); var comando = new ChamadaDTO { AnoTurma = 2000 }; //act AulaService.RealizaChamada(comando); // assert is [ExpectedException] }
// PUT: api/Chamada/5 public void Put(int id, [FromBody] ChamadaDTO value) { }
// POST: api/Chamada public void Post([FromBody] ChamadaDTO value) { _aulaService.RealizaChamada(value); }
public override void CreateView(View view) { if (!string.IsNullOrWhiteSpace(_classeNome) && BaseActivity != null) { BaseActivity.SupportActionBar.Subtitle = $"Classe {_classeNome}"; } _textMes = view.FindViewById <TextView>(Resource.Id.TextMes); _textVisitantes = view.FindViewById <EditText>(Resource.Id.TextVisitantes); _textBiblias = view.FindViewById <EditText>(Resource.Id.TextBiblias); _textRevistas = view.FindViewById <EditText>(Resource.Id.TextRevistas); _textOferta = view.FindViewById <EditText>(Resource.Id.TextOferta); _textOferta.AddTextChangedListener(new MoneyFormattingTextWatcher()); view.FindViewById <ImageButton>(Resource.Id.BtnPreviusDay).Click += (sender, e) => AtualizarData(data => ProximaData(data, -1)); view.FindViewById <ImageButton>(Resource.Id.BtnNextDay).Click += (sender, e) => AtualizarData(data => ProximaData(data)); _adapter = new CheckBoxAdapter <AlunoDTO, AlunoViewHolder>(Resource.Layout.alunoCheckItem); var recyclerView = view.FindViewById <RecyclerView>(Resource.Id.RecyclerView); recyclerView.SetAdapter(_adapter); recyclerView.SetLayoutManager(new LinearLayoutManager(Activity, LinearLayoutManager.Vertical, false)); _dataAtual = ProximaData(_dataAtual); AtualizarDados(_dataAtual); Salvar += (sender, e) => { var dto = new ChamadaDTO(); if (!string.IsNullOrWhiteSpace(_textVisitantes.Text)) { dto.Visitantes = Convert.ToInt32(_textVisitantes.Text); } if (!string.IsNullOrWhiteSpace(_textBiblias.Text)) { dto.Biblias = Convert.ToInt32(_textBiblias.Text); } if (!string.IsNullOrWhiteSpace(_textRevistas.Text)) { dto.Revistas = Convert.ToInt32(_textRevistas.Text); } if (!string.IsNullOrWhiteSpace(_textOferta.Text)) { dto.Oferta = Convert.ToDecimal(_textOferta.Text); } var alunosPresentes = _adapter.GetChecked(); if (alunosPresentes.Any()) { dto.Presencas = new List <AlunoDTO>(alunosPresentes.Select(x => new AlunoDTO { Id = x.Id, Nome = x.Nome })); } new ClasseRepositorio(App.Instancia.Token) .SalvarChamada(_setor, _congregacao, _classeId, _dataAtual, dto); }; }
public async void SalvarChamada(int setor, int congregacao, int classe, DateTime data, ChamadaDTO dto) { var config = CriarRequestConfig(); config.EndPoint = "Setores/{setor}/Congregacoes/{congregacao}/Classes/{classe}/Chamadas/{data}"; config.AddParam("{setor}", setor); config.AddParam("{congregacao}", congregacao); config.AddParam("{classe}", classe); config.AddParam("{data}", data.ToString("yyyy-MM-dd")); await new WebRequestHelper(config).Post(dto); }