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> 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)); }