Exemple #1
0
 public Agendamento(int codigo, DateTime dataAgendamento, Cliente cliente, Servico servico, StatusAgendamento statusAgendamento)
 {
     Codigo            = codigo;
     DataAgendamento   = dataAgendamento;
     Cliente           = cliente;
     Servico           = servico;
     StatusAgendamento = statusAgendamento;
 }
Exemple #2
0
        public void AlterarStatusLaboratorio(AgendamentoDto agendamentoDto, StatusAgendamento status)
        {
            var agendamento = contexo.Agendamentos.Where(x => x.Status == StatusAgendamento.Aberto);

            if (agendamentoDto.Id != 0)
            {
                agendamento = agendamento.Where(x => x.Id == agendamentoDto.Id);
            }

            if (agendamentoDto.IdDisciplina != 0)
            {
                agendamento = agendamento.Where(x => x.Disciplina.Id == agendamentoDto.IdDisciplina);
            }

            if (agendamentoDto.IdLaboratorio != 0)
            {
                agendamento = agendamento.Where(x => x.Laboratorio.Id == agendamentoDto.IdLaboratorio);
            }

            if (agendamentoDto.HorarioInicial != null && agendamentoDto?.HorarioInicial != DateTime.MinValue)
            {
                agendamento = agendamento.Where(x => x.HorarioInicial == agendamentoDto.HorarioInicial);
            }

            if (agendamentoDto.HorarioFinal != null && agendamentoDto?.HorarioFinal != DateTime.MinValue)
            {
                agendamento = agendamento.Where(x => x.HorarioFinal == agendamentoDto.HorarioFinal);
            }

            var result = agendamento.ToList();

            if (result.Count == 0)
            {
                throw new ObjectNotFoundException("Não foi encontrado nenhum agendamento.");
            }

            if (result.Count > 1)
            {
                throw new Exception("Inclua mais informações, para que seja liberado somente um horário.");
            }

            var horario = result.First();

            if (horario.HorarioFinal < DateTime.Now)
            {
                throw new Exception("Horárío já finalizado.");
            }

            if (horario.HorarioInicial < DateTime.Now)
            {
                throw new Exception("Horário em andamento.");
            }

            horario.Status = status;
            contexo.Agendamentos.AddOrUpdate(horario);
            contexo.SaveChanges();
        }
Exemple #3
0
 public Task <bool> CompleteSchedule(User user, int scheduleId, StatusAgendamento status)
 {
     try
     {
         return(Task.FromResult(_agendaRepository.ChangeScheduleStatus(user, scheduleId, status)));
     }
     catch
     {
         return(Task.FromResult(false));
     }
 }
        public bool ChangeScheduleStatus(User user, int scheduleId, StatusAgendamento status = StatusAgendamento.Confirmado)
        {
            var agendaAppointment = Context.AgendaAppointments
                                    .FirstOrDefault(o => o.ID == scheduleId &&
                                                    o.AgendaSchedule.Agenda.ProfessionalID == user.ProfessionalID);

            if (agendaAppointment != null)
            {
                agendaAppointment.Status = status;
                Context.SaveChanges();

                return(true);
            }

            return(false);
        }
        public async Task <IActionResult> CompleteSchedule([FromQuery] int scheduleId, [FromQuery] StatusAgendamento status)
        {
            var agendaRepository = new AgendaRepository(_context);
            var agendaService    = new AgendaService(agendaRepository);
            var userRepository   = new UserRepository(_context);

            var authenticadedUser = ((ClaimsIdentity)User.Identity).Claims.FirstOrDefault()?.Value;
            var user = await userRepository.GetUserFromEmailOrOauthID(authenticadedUser);

            if (user == null)
            {
                return(NotFound("Usuário não encontrado"));
            }

            if (agendaService.CompleteSchedule(user, scheduleId, status).Result)
            {
                return(Ok());
            }

            return(NotFound("Agendamento não encontrado"));
        }