public IActionResult Create(DoctorDetailViewModel vm) { // Check if model is valid if (ModelState.IsValid) { Doctor doctor = converter.ViewModelToModel(vm); long id = doctorRepository.Insert(doctor); return(RedirectToAction("Details", new { id })); } else { vm.Genders = converter.GetGenders(); return(View()); } }
public IActionResult Edit(UserViewModel viewModel) { // Get user id long id = GetUserId(); // Execute correct action based on role if (HttpContext.User.IsInRole("patient")) { viewModel.Patient.Id = id; Patient patient = patientConverter.ViewModelToModel(viewModel.Patient); patientRepository.Update(patient); } else if (HttpContext.User.IsInRole("doctor")) { viewModel.Doctor.EmployeeNumber = id; Doctor doctor = doctorConverter.ViewModelToModel(viewModel.Doctor); doctorRepository.Update(doctor); } return(RedirectToAction("index", "Profile")); }