[ValidateAntiForgeryToken] //Prevenimos cambios externos public async Task <IActionResult> Edit(int id, [Bind("PubIntIdPaciente,PubStrNombre,PubStrSeguro,PubStrCodigoPostal,PubStrTelefono,PubStrDireccion,PubStrEmail")] Paciente paciente) { if (id != paciente.PubIntIdPaciente) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(paciente); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PacienteExists(paciente.PubIntIdPaciente)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(paciente)); }
[HttpPost] //Metodo editar encargado del proceso POST al formulario BD public async Task <IActionResult> Edit(int id, [Bind("PubIntIdEspecialidad,PubStrDescripcion")] Especialidad especialidad) { if (id != especialidad.PubIntIdEspecialidad) { return(NotFound()); } if (ModelState.IsValid) { _context.Update(especialidad); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(especialidad)); }
[ValidateAntiForgeryToken] //Prevenimos cambios externos public async Task <IActionResult> Edit(int id, [Bind("PubIntIdDoctor,PubStrNombre,PubStrCredencial,PubStrHospital,PubStrTelefono,PubStrEmail")] Doctor doctor, int PubIntIdEspecialidad) { if (id != doctor.PubIntIdDoctor) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(doctor); await _context.SaveChangesAsync(); var doctorEspecialidad = await _context.DoctorEspecialidad .FirstOrDefaultAsync(me => me.PubIntIdDoctor == id); _context.Remove(doctorEspecialidad); await _context.SaveChangesAsync(); doctorEspecialidad.PubIntIdEspecialidad = PubIntIdEspecialidad; _context.Add(doctorEspecialidad); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DoctorExists(doctor.PubIntIdDoctor)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(doctor)); }