Exemple #1
0
        /// <summary>
        /// Handle form submission.
        /// </summary>
        /// <returns></returns>
        private async Task HandleSubmit()
        {
            var requestUrl =
                Env.IsDevelopment()
                    ? "https://localhost:5009/client-gw/appointment"
                    : "https://localhost:8088/client-gw/appointment";

            Status = APIOperationStatus.POST_Pending;
            StateHasChanged();

            if (!PatientInApprovedList())
            {
                ToastService.ShowError(
                    "Patient not found. Please ensure that the personal details entered are correct and try again.");
                Status = APIOperationStatus.GET_Success;
                StateHasChanged();
                return;
            }

            if (AppointmentAlreadySubmitted())
            {
                ToastService.ShowError(
                    "There selected consultant already has an appointment scheduled at the selected time.");
                Status = APIOperationStatus.GET_Success;
                StateHasChanged();
                return;
            }

            try
            {
                var dto = CreateDTO();

                var result = await ApiRequestService.HandlePostRequest(requestUrl, dto);

                Status = APIOperationStatus.POST_Success;

                var consultant = ViewModel.ConsultantList.FirstOrDefault(c => c.Id == result.ConsultantId);
                var timeSlot   = ViewModel.TimeSlotList.FirstOrDefault(ts => ts.Id == result.TimeSlotId);

                ToastService.ShowSuccess(
                    $"Appointment with Dr. {consultant?.FirstName} {consultant?.LastName} ({consultant?.Specialty}) on {result.Date:dd/MM/yyyy} from {timeSlot?.StartTime:hh:mm} to {timeSlot?.EndTime:hh:mm} successfully scheduled.");

                NavigationManager.NavigateTo("/");
            }
            catch (Exception e)
            {
                ToastService.ShowError(
                    "There was an error submitting your request. Please ensure that the entered is correct data and retry.");
            }
        }