public IActionResult Editar(TipoInvestigacionViewModel TipoInv_VM) { if (ModelState.IsValid) { try { TipoInvestigacionesRepository tipoInvestigacionesRepository = new TipoInvestigacionesRepository(); var tipoinvestigacionResult = tipoInvestigacionesRepository.GetTipoinvestigacionByNombre(TipoInv_VM.Nombre.ToLower()); //Regex regex = new Regex(@"^[a-zA-ZñÑáéíóúÁÉÍÓÚ\s 0-9 ]+$"); Regex regex = new Regex(@"^[a-zA-ZñÑáéíóúÁÉÍÓÚ\s ]+$"); bool resultado = true; resultado = regex.IsMatch(TipoInv_VM.Nombre); if (!resultado) { ModelState.AddModelError("", "No se aceptan números y caracteres especiales en el nombre (Solo: a-z, A-Z)."); return(View(TipoInv_VM)); } Regex regexNoNumStart = new Regex(@"[0-9]| $"); bool resultadoNoNumStart = false; string textoFirstChart = TipoInv_VM.Nombre.Substring(0, 1); resultadoNoNumStart = regexNoNumStart.IsMatch(textoFirstChart); if (resultadoNoNumStart) { ModelState.AddModelError("", "No se permite iniciar con NÚMERO o con ESPACIO."); return(View(TipoInv_VM)); } if (tipoinvestigacionResult == null) { tipoInvestigacionesRepository.UpdateTipoInvetigacionVM(TipoInv_VM); return(RedirectToAction("Tipoinvestigacion", "Administrador")); } else if (tipoinvestigacionResult.IdTipoInvestigacion == TipoInv_VM.IdTipoInvestigacion) { tipoinvestigacionResult.Nombre = TipoInv_VM.Nombre; tipoInvestigacionesRepository.Update(tipoinvestigacionResult); return(RedirectToAction("Tipoinvestigacion", "Administrador")); } else { ModelState.AddModelError("", "Ya existe este tipo de investigación."); return(View(TipoInv_VM)); } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(View(TipoInv_VM)); } } else { return(View(TipoInv_VM)); } }
public void InsertTipoInvestigacionVM(TipoInvestigacionViewModel tipoInv_Vm) { Tipoinvestigacion tInv = new Tipoinvestigacion() { Nombre = tipoInv_Vm.Nombre }; Insert(tInv); }
public void UpdateTipoInvetigacionVM(TipoInvestigacionViewModel tipoInv_VM) { var TipoInvResult = GetById(tipoInv_VM.IdTipoInvestigacion); if (TipoInvResult != null) { TipoInvResult.Nombre = tipoInv_VM.Nombre; Update(TipoInvResult); } }
public IActionResult Eliminar(TipoInvestigacionViewModel TipoInv_VM) { TipoInvestigacionesRepository tipoInvestigacionesRepository = new TipoInvestigacionesRepository(); var tipoinvestigacionResult = tipoInvestigacionesRepository.GetById(TipoInv_VM.IdTipoInvestigacion); if (tipoinvestigacionResult != null) { tipoInvestigacionesRepository.Delete(tipoinvestigacionResult); } return(RedirectToAction("Tipoinvestigacion", "Administrador")); }