コード例 #1
0
        public override async Task <ActionResult <ListAppointmentResponse> > HandleAsync([FromQuery] ListAppointmentRequest request, CancellationToken cancellationToken)
        {
            var response = new ListAppointmentResponse(request.CorrelationId());

            var scheduleSpec = new ScheduleForDateAndClinicSpecification(_settings.ClinicId, _settings.TestDate);

            int totalSchedules = await _repository.CountAsync <Schedule, Guid>(scheduleSpec);

            if (totalSchedules <= 0)
            {
                response.Appointments = new List <AppointmentDto>();
                response.Count        = 0;
                return(Ok(response));
            }

            var schedule = (await _repository.ListAsync <Schedule, Guid>(scheduleSpec)).First();

            var appointmentSpec = new AppointmentByScheduleIdSpecification(schedule.Id);
            var appointments    = (await _repository.ListAsync <Appointment, Guid>(appointmentSpec)).ToList();

            var myAppointments = _mapper.Map <List <AppointmentDto> >(appointments);

            response.Appointments = myAppointments.OrderBy(a => a.Start).ToList();
            response.Count        = response.Appointments.Count;

            return(Ok(response));
        }
コード例 #2
0
        public async Task Handle(AppointmentConfirmedEvent appointmentConfirmedEvent, CancellationToken cancellationToken)
        {
            var scheduleSpec = new ScheduleForDateAndClinicSpecification(_settings.ClinicId, _settings.TestDate);
            // Note: In this demo this only works for appointments scheduled on TestDate
            var schedule = (await _scheduleRepository.ListAsync <Schedule, Guid>(scheduleSpec)).FirstOrDefault();

            Guard.Against.Null(schedule, nameof(Schedule));

            var appointmentToConfirm = schedule.Appointments.FirstOrDefault(a => a.Id == appointmentConfirmedEvent.AppointmentId);

            appointmentToConfirm.Confirm(appointmentConfirmedEvent.DateTimeEventOccurred);

            await _scheduleRepository.UpdateAsync <Schedule, Guid>(schedule);
        }