public Mensagem AtualizarAgendamento(AgendamentoComIdViewModel agendamentoComIdViewModel)
        {
            var listaAgendamentosRetorno = new List <Agendamento>();

            agendamentoComIdViewModel.DataHoraAgendamento = TimeZoneInfo.ConvertTime(agendamentoComIdViewModel.DataHoraAgendamento, TimeZoneInfo.FindSystemTimeZoneById("E. South America Standard Time"));
            agendamentoComIdViewModel.DataHoraRegistro    = TimeZoneInfo.ConvertTime(agendamentoComIdViewModel.DataHoraRegistro, TimeZoneInfo.FindSystemTimeZoneById("E. South America Standard Time"));

            listaAgendamentosRetorno = this.agendamentoRepository.BuscarAgendamentoEntreDataEHora(agendamentoComIdViewModel.DataHoraAgendamento.Subtract(new TimeSpan(0, 14, 0)), agendamentoComIdViewModel.DataHoraAgendamento.Add(new TimeSpan(0, 14, 0)), Guid.Empty, new Guid(agendamentoComIdViewModel.IdMedico)).ToList();
            if (listaAgendamentosRetorno.Count() > 1 || (listaAgendamentosRetorno.Count == 1 && (listaAgendamentosRetorno.Find(a => a.IdAgendamento.ToString().Equals(agendamentoComIdViewModel.IdAgendamento)) == null)))
            {
                return(new Mensagem(0, "Este médico já possui uma consulta marcada neste intervalo de hora!"));
            }

            listaAgendamentosRetorno = this.agendamentoRepository.BuscarAgendamentoEntreDataEHora(agendamentoComIdViewModel.DataHoraAgendamento.Subtract(new TimeSpan(0, 14, 0)), agendamentoComIdViewModel.DataHoraAgendamento.Add(new TimeSpan(0, 14, 0)), new Guid(agendamentoComIdViewModel.IdPaciente), Guid.Empty).ToList();
            if (listaAgendamentosRetorno.Count() > 1 || (listaAgendamentosRetorno.Count == 1 && (listaAgendamentosRetorno.Find(a => a.IdAgendamento.ToString().Equals(agendamentoComIdViewModel.IdAgendamento)) == null)))
            {
                return(new Mensagem(0, "Este paciente já possui uma consulta marcada neste intervalo de hora!"));
            }

            if (this.agendamentoRepository.AtualizarAgendamento(new Agendamento(new Guid(agendamentoComIdViewModel.IdAgendamento), agendamentoComIdViewModel.DataHoraAgendamento, agendamentoComIdViewModel.DataHoraRegistro, agendamentoComIdViewModel.Observacoes, new Guid(agendamentoComIdViewModel.IdMedico), new Guid(agendamentoComIdViewModel.IdPaciente))))
            {
                return(new Mensagem(1, "Agendamento atualizado com sucesso!"));
            }

            return(new Mensagem(0, "Falha ao atualizar o agendamento!"));
        }
Beispiel #2
0
        public void AtualizarAgendamentoTest()
        {
            // given
            var agendamento = new AgendamentoComIdViewModel("418A3CF2-A78F-4AD2-84C6-712638AD048B", DateTime.Now, DateTime.Now, "Nada", "C62ACB1E-94E1-487F-0F68-08D79090D2CB", "16E16A8D-469F-4286-A470-08D78CC0F920");

            this.agendamentoRepositoryMock.Setup(a => a.BuscarAgendamentoEntreDataEHora(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <Guid>(), It.IsAny <Guid>())).Returns(new List <Agendamento>());
            this.agendamentoRepositoryMock.Setup(a => a.AtualizarAgendamento(It.IsAny <Agendamento>())).Returns(true);

            var agendamentoService = new AgendamentoService(this.agendamentoRepositoryMock.Object, this.consultaRepositoryMock.Object);

            // when
            var resultado = agendamentoService.AtualizarAgendamento(agendamento);

            // then
            Assert.NotNull(resultado);
            Assert.True(resultado.Id == 1);
        }
Beispiel #3
0
        public void NaoAtualizarAgendamentoDentroIntervaloMesmoPacienteTempoTest()
        {
            // given
            var agendamento = new AgendamentoComIdViewModel("418A3CF2-A78F-4AD2-84C6-712638AD048B", DateTime.Now, DateTime.Now, "Nada", "C62ACB1E-94E1-487F-0F68-08D79090D2CB", "16E16A8D-469F-4286-A470-08D78CC0F920");
            var lista       = new List <Agendamento>();

            lista.Add(new Agendamento());

            this.agendamentoRepositoryMock.Setup(a => a.BuscarAgendamentoEntreDataEHora(agendamento.DataHoraAgendamento.Subtract(new TimeSpan(0, 14, 0)), agendamento.DataHoraAgendamento.Add(new TimeSpan(0, 14, 0)), new Guid("16E16A8D-469F-4286-A470-08D78CC0F920"), It.IsAny <Guid>())).Returns(lista);
            this.agendamentoRepositoryMock.Setup(a => a.AtualizarAgendamento(It.IsAny <Agendamento>())).Returns(true);

            var agendamentoService = new AgendamentoService(this.agendamentoRepositoryMock.Object, this.consultaRepositoryMock.Object);

            // when
            var resultado = agendamentoService.AtualizarAgendamento(agendamento);

            // then
            Assert.NotNull(resultado);
            Assert.True(resultado.Id == 0);
        }
 public Mensagem AtualizarAgendamento([FromBody] AgendamentoComIdViewModel agendamentoComIdViewModel)
 {
     return this.agendamentoService.AtualizarAgendamento(agendamentoComIdViewModel);
 }