public async Task<ActionResult> EditarInstructor(TER_INSTRUCTORMODEL _model) { if (ModelState.IsValid) { try { // comprobar la existencia del nombre var _test = await _context.TER_INSTRUCTOR.FirstOrDefaultAsync(i => i.NOMBRE == _model.NOMBRE); //bool _nombreRepetido = false; //_nombreRepetido = (_test.ID != _model.ID && _test.NOMBRE == _model.NOMBRE) ? true : false; if (_test != null) { if (_test.ID != _model.ID) { ModelState.AddModelError("", "Ya existe un registro con este nombre, por favor elija otro!"); return View(_model); } else { // get entity var _entity = new TER_INSTRUCTOR(); _entity = await _context.TER_INSTRUCTOR.FindAsync(_model.ID); _entity.NOMBRE = _model.NOMBRE; _entity.INSTITUCION = _model.INSTITUCION; // guardar en el context _context.Entry(_entity).State = EntityState.Modified; await _context.SaveChangesAsync(); // to lista de Fases return RedirectToAction("Instructores", "Configuraciones"); } } else { // get entity var _entity = new TER_INSTRUCTOR(); _entity = await _context.TER_INSTRUCTOR.FindAsync(_model.ID); _entity.NOMBRE = _model.NOMBRE; _entity.INSTITUCION = _model.INSTITUCION; // guardar en el context _context.Entry(_entity).State = EntityState.Modified; await _context.SaveChangesAsync(); // to lista de Fases return RedirectToAction("Instructores", "Configuraciones"); } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return View(_model); } } return View(_model); }
public async Task<ActionResult> NuevoInstructor(TER_INSTRUCTORMODEL _model) { if (ModelState.IsValid) { try { // coprobar la existencia del nombre if (_context.TER_INSTRUCTOR.FirstOrDefault(i => i.NOMBRE == _model.NOMBRE) != null) { ModelState.AddModelError("", "Ya existe un registro con este nombre, por favor elija otro!"); return View(_model); } else { // get entity var _entity = new TER_INSTRUCTOR { NOMBRE = _model.NOMBRE, INSTITUCION = _model.INSTITUCION }; // guardar en el context _context.TER_INSTRUCTOR.Add(_entity); await _context.SaveChangesAsync(); // to lista de Fases return RedirectToAction("Instructores", "Configuraciones"); } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return View(_model); } } return View(_model); }
//editar Instructor // get public async Task<ActionResult> EditarInstructor(int? ID) { // comprobar la nulidad de ID if (ID == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } //get entity var _entity = await _context.TER_INSTRUCTOR.FindAsync(ID); // comprobar si existe un registro con es id if (_entity == null) { return HttpNotFound(); } // set model var _model = new TER_INSTRUCTORMODEL { ID = _entity.ID, NOMBRE = _entity.NOMBRE, INSTITUCION = _entity.INSTITUCION }; // to view return View(_model); }
// crear Instructor //get public ActionResult NuevoInstructor() { // get model var _model = new TER_INSTRUCTORMODEL(); return View(_model); }