コード例 #1
0
        public async Task <IActionResult> GetAsync([FromQuery] DateTime?after = null)
        {
            //todo: authentication

            //todo: get user id and of dr or patient via auth
            bool isDr = true;
            int  id   = -1;

            Task <IEnumerable <Timeslot> > apointmentsTask;

            if (isDr)
            {
                apointmentsTask = _ApointmentRepo.GetDoctorTimeslotsAsync(id);
            }
            else
            {
                apointmentsTask = _ApointmentRepo.GetPatientTimeslotsAsync(id);
            }

            IEnumerable <Timeslot> apointments;

            // check for if the person's ID cannot be found.
            // see https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/exception-handling-task-parallel-library#attached-child-tasks-and-nested-aggregateexceptions
            try
            {
                apointments = await apointmentsTask;
            } catch (AggregateException e)
            {
                var exception = e.Flatten();

                if (exception.InnerExceptions is not null && exception.InnerException is ArgumentException)
                {
                    _logger.LogError(exception.InnerException.Message);
                    _logger.LogError(e.StackTrace);

                    return(NotFound());
                }