public ActionResult Actualizar(RolView RolView) { try { string id = Request.Form["txtId"]; string usuarioRol = Request.Form["txtUsuarioRol"]; string nombreRol = Request.Form["txtNombreRol"]; string correoRol = Request.Form["txtCorreoRol"]; string claveRol = Request.Form["txtClaveRol"]; Rol d = new Rol(); d.Id = int.Parse(id); d.Nombre = nombreRol; RolRepository dr = new RolRepository(); d = dr.Actualizar(d); if (d.Id == 0) { RolView.Mensaje = "Hubo un error al crear el Rol"; return(View("Crear", RolView)); } RolView dd = new RolView(); dd.Mensaje = "Rol Actualizado"; dd.Rol = d; return(View("Obtener", dd)); } catch (Exception ex) { return(View("Mensaje", new RolView { Mensaje = ex.Message })); } }
public ActionResult Crear(RolView RolView) { try { string nombreRol = Request.Form["txtNombreRol"]; #region Verificar is ya existe el código del Rol RolRepository dr = new RolRepository(); Rol d = dr.ObtenerPorNombre(nombreRol.Trim()); if (d != null) { RolView.Rol.Nombre = nombreRol; RolView.Mensaje = "El código del Rol ya existe"; return(View("Crear", RolView)); } else { d = new Rol(); d.Nombre = nombreRol; d = dr.Actualizar(d); if (d.Id == 0) { RolView.Mensaje = "Hubo un error al crear el Rol"; return(View("Crear", RolView)); } } #endregion RolView pp = new RolView(); pp.Mensaje = "Rol Creado"; return(View("Crear", pp)); } catch (Exception ex) { return(View("Mensaje", new RolView { Mensaje = ex.Message })); } }