public ActionResult Index(RolView dcv) { try { string nombreRol = Request.Form["txtNombreRol"]; RolRepository dr = new RolRepository(); List <Rol> Roles = dr.Listar(nombreRol); dcv.Rol = new Rol(); dcv.Rol.Nombre = nombreRol; dcv.Roles = Roles; string mensaje = ""; if (Roles.Count == 0) { mensaje = "No existen Roles para el criterio de búsqueda"; } dcv.Mensaje = mensaje; return(View(dcv)); } catch (Exception ex) { return(View("Mensaje", new RolView { Mensaje = ex.Message })); } }
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 Roles(string userID) { var rolMarager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(db)); var usuarioManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); var roles = rolMarager.Roles.ToList(); var usuarios = usuarioManager.Users.ToList(); var usuario = usuarios.Find(u => u.Id == userID); var rolesView = new List <RolView>(); if (usuario.Roles != null) { foreach (var item in usuario.Roles) { var role = roles.Find(r => r.Id == item.RoleId); var roleView = new RolView { RoleID = role.Id, Name = role.Name, }; rolesView.Add(roleView); } } var userView = new UserView() { EMail = usuario.Email, Name = usuario.UserName, UserID = usuario.Id, Roles = rolesView.OrderBy(r => r.Name).ToList() }; return(View(userView)); }
public ActionResult Crear() { try { RolView dv = new RolView(); return(View(dv)); } catch (Exception ex) { return(View("Mensaje", new RolView { Mensaje = ex.Message })); } }
public ActionResult Obtener(string id) { try { RolView dv = new RolView(); dv.Mensaje = ""; RolRepository dr = new RolRepository(); Rol p = dr.Obtener(id); dv.Rol = p; return(View("Obtener", dv)); } 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 })); } }