public async Task <IActionResult> Create([Bind("PatientId,AppointmentDate,FromHour,FromMinute,ToHour,ToMinute,AppointmentDuration")] Appointment appointment)
        {
            if (ModelState.IsValid)
            {
                int success = await _appointmentRepository.SaveAppointmentAsync(AppointmentConverter.AppointmentForDb(appointment));

                if (success != 0)
                {
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    ViewBag.ListOfPatients = PatientConverter.ListForFrontEnd(await _patientRepository.GetAllPatientsAsync());
                    ViewBag.ListOfHours    = hours.Hours;
                    ViewBag.ListOfMinutes  = hours.Minutes;

                    ViewBag.ErrorMessage = "Something went wrong while creating appointment list entry, please try again...";
                }
            }

            ViewBag.ListOfPatients = PatientConverter.ListForFrontEnd(await _patientRepository.GetAllPatientsAsync());
            ViewBag.ListOfHours    = hours.Hours;
            ViewBag.ListOfMinutes  = hours.Minutes;

            return(View(appointment));
        }
        public async Task <IActionResult> Create()
        {
            ViewBag.ListOfPatients = PatientConverter.ListForFrontEnd(await _patientRepository.GetAllPatientsAsync());
            ViewBag.ListOfHours    = hours.Hours;
            ViewBag.ListOfMinutes  = hours.Minutes;

            return(View());
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,PatientId,AppointmentDate,FromHour,FromMinute,ToHour,ToMinute,AppointmentDuration")] Appointment appointment)
        {
            if (id != appointment.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var app = AppointmentConverter.AppointmentForDb(appointment);

                    var succes = await _appointmentRepository.UpdateAppointmentAsync(app);

                    if (succes != 0)
                    {
                        return(RedirectToAction(nameof(Index)));
                    }
                    else
                    {
                        ViewBag.ListOfPatients = PatientConverter.ListForFrontEnd(await _patientRepository.GetAllPatientsAsync());
                        ViewBag.ListOfHours    = hours.Hours;
                        ViewBag.ListOfMinutes  = hours.Minutes;

                        ViewBag.ErrorMessage = "Something went wrong while updating patient list entry, please try again...";
                    }
                }
                catch (SqlException)
                {
                    var entry = await _appointmentRepository.GetAppointmentByIdAsync(appointment.Id);

                    if (entry is null)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            ViewBag.ListOfPatients = PatientConverter.ListForFrontEnd(await _patientRepository.GetAllPatientsAsync());
            ViewBag.ListOfHours    = hours.Hours;
            ViewBag.ListOfMinutes  = hours.Minutes;

            return(View(appointment));
        }
        public async Task <IActionResult> Index()
        {
            try
            {
                var patients = PatientConverter.ListForFrontEnd(await _patientRepository.GetAllPatientsAsync());

                return(View(patients));
            }
            catch (SqlException ex)
            {
                ViewBag.ErrorMessage = $"Error: { ex.Message }";
            }

            return(View());
        }
        // GET: Appointment/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var app = await _appointmentRepository.GetAppointmentByIdAsync(id.Value);//await _dbDataAccess.GetAppointmentByIdAsync(id.Value);

            if (app == null)
            {
                return(NotFound());
            }

            ViewBag.ListOfPatients = PatientConverter.ListForFrontEnd(await _patientRepository.GetAllPatientsAsync());
            ViewBag.ListOfHours    = hours.Hours;
            ViewBag.ListOfMinutes  = hours.Minutes;

            var appointment = await AppointmentConverter.AppointmentForFrontEnd(app, _patientRepository);

            return(View(appointment));
        }