public ActionResult AddOrEdit(Rol rol) { if (rol.RolId == 0) { db.Roles.Add(rol); var response = DBHelper.SaveChanges(db); if (response.Succeeded) { UsuariosHelper.CheckRole(rol.Nombre); return(Json(new { success = true, message = "ROL AGREGADO" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = true, message = response.Message }, JsonRequestBehavior.AllowGet)); } } else { db.Entry(rol).State = EntityState.Modified; var response = DBHelper.SaveChanges(db); if (response.Succeeded) { UsuariosHelper.UpdateRole(Session["CurrentRol"].ToString(), rol.Nombre); return(Json(new { success = true, message = "ROL ACTUALIZADO" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = true, message = response.Message }, JsonRequestBehavior.AllowGet)); } } }
protected void btnAceptar_Click(object sender, EventArgs e) { try { this.usu = new Usuarios(); this.usu.Nombre = this.txtnombre.Text; this.usu.Apellido = this.txtapellido.Text; this.usu.Apellido2 = this.txtapellido2.Text; this.usu.Cedula = this.txtcedula.Text; this.usu.Correo = this.txtcorreo.Text; this.usu.Nombre_usuario = this.txtnombreUsu.Text; this.usu.Tipo = this.DropDownList1.SelectedValue; this.usu.Clave = CrearPassword(10); EnviarCorreos(); this.usu.Opc = 1; this.usuHelper = new UsuariosHelper(usu); this.usuHelper.AgregarUsuarios(); ScriptManager.RegisterStartupScript(this, typeof(Page), "mensajeDeconfirmacion", "mensajeDeconfirmacion('" + "" + "');", true); } catch (Exception) { ScriptManager.RegisterStartupScript(this, typeof(Page), "mensajeError", "mensajeError('" + "" + "');", true); } }
protected void btnAceptar_Click(object sender, EventArgs e) { if (IsValid) { try { this.usu = new Usuarios(); this.usu.Nombre = this.txtnombre.Text; this.usu.Apellido = this.txtapellido.Text; this.usu.Apellido2 = this.txtapellido2.Text; this.usu.Nombre_usuario = this.txtusuario.Text; this.usu.Clave = this.txtnuevaclave.Text; // la cedula no se actualiza pero si es necesaria indicar ese valor puesto que el usuario se actualiza con respecto a su numero de cedula this.usu.Cedula = Usuarios.CedulaActualizar; this.usu.Opc = 4; this.usuH = new UsuariosHelper(usu); this.usuH.ActualizarUsuarios(); ScriptManager.RegisterStartupScript(this, typeof(Page), "mensajeDeconfirmacion", "mensajeDeconfirmacion('" + "" + "');", true); } catch (Exception) { ScriptManager.RegisterStartupScript(this, typeof(Page), "mensajeError", "mensajeError('" + "" + "');", true); } } }
private void CambiarClave() { try { this.user = new Usuarios(); this.user.Usuario = this.stsUser.Text; this.user.Clave = EncryptionHelper.Encrypt(this.txtClave.Text); this.user.opc = 6; this.userHelper = new UsuariosHelper(user); /* * this.bitacora = new Bitacora(); * this.bitacora.Usuario = this.user.Usuario; * this.bitacora.Movimiento = "Actualizar"; * this.bitacora.Detalle = "Se actualizo el usuario correctamente " + this.txtUsuario.Text; * this.bitacora.opc = 5; * this.bitH = new BitacoraHelper(bitacora); * this.bitH.LogMovimientos(); */ this.userHelper.CambiarClave(); MessageBox.Show("La clave ha sido actualizada"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public async Task <ActionResult> AddOrEdit(Usuario usuario) { if (usuario.UsuarioId == 0) { db.Usuarios.Add(usuario); var response = DBHelper.SaveChanges(db); if (response.Succeeded) { var rol = db.Roles.Where(r => r.RolId == usuario.RolId).FirstOrDefault(); var random = new Random(); var password = string.Format("{0}{1}{2:04}*", usuario.Nombres.Trim().ToUpper().Substring(0, 1), usuario.Apellidos.Trim().ToLower().Substring(0, 1) + "Lt", random.Next(10000)); UsuariosHelper.CreateUserASP(usuario.NombreUsuario, rol.Nombre, password); var subject = "Bienvenido a la Plataforma de Campañas"; var body = string.Format(@" <h1>Bienvenido a la Plataforma de Campañas</h1> <p>Tu Usuario es: <strong>{1}</strong></p> <p>Tu password es: <strong>{0}</strong></p> <p>Link de la Plataforma: <a href='https://servicios.litoprocess.com/Campanias'>servicios.litoprocess.com/Campanias</a>", password, usuario.NombreUsuario); await MailHelper.SendMail(usuario.NombreUsuario, "*****@*****.**", subject, body); UsuariosHelper.AddRole(usuario.NombreUsuario, rol.Nombre, password); return(Json(new { success = true, message = "USUARIO AGREGADO" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = true, message = response.Message }, JsonRequestBehavior.AllowGet)); } } else { db.Entry(usuario).State = EntityState.Modified; var response = DBHelper.SaveChanges(db); if (response.Succeeded) { var currentUser = Session["UsuarioEditado"].ToString(); var currentRol = (int)Session["RolEditado"]; var currentRolNombre = db.Roles.Where(r => r.RolId == currentRol).FirstOrDefault(); var newRol = db.Roles.Where(r => r.RolId == usuario.RolId).FirstOrDefault(); if (currentUser == usuario.NombreUsuario || currentRol == newRol.RolId) { UsuariosHelper.UpdateUserName(currentUser, usuario.NombreUsuario.ToLower(), currentRolNombre.Nombre, newRol.Nombre); } return(Json(new { success = true, message = "USUARIO ACTUALIZADO" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = true, message = response.Message }, JsonRequestBehavior.AllowGet)); } } }
private void CheckRolesAndSuperUser() { UsuariosHelper.CheckRole("SuperAdmin"); UsuariosHelper.CheckRole("Admin"); UsuariosHelper.CheckRole("teacher"); UsuariosHelper.CheckSuperUser(); }
public HttpResponseMessage SaveUser([FromBody] Usuarios Model) { bool SuccessfullSave = UsuariosHelper.Save(Model); if (!SuccessfullSave) { throw new HttpResponseException(HttpStatusCode.InternalServerError); } return(Request.CreateResponse(HttpStatusCode.Created)); }
public HttpResponseMessage GetUserById(int Id) { if (!UsuariosHelper.UserExist(Id)) { throw new HttpResponseException(HttpStatusCode.NotFound); } Usuarios usr = UsuariosHelper.GetUsuarioByPrimaryKey(Id); return(Request.CreateResponse(HttpStatusCode.OK, usr)); }
public HttpResponseMessage Save(Usuarios usr) { bool SuccesfullSaved = UsuariosHelper.Save(usr); if (!SuccesfullSaved) { throw new HttpResponseException(HttpStatusCode.InternalServerError); } return(Request.CreateResponse(HttpStatusCode.Created)); }
public HttpResponseMessage GetAllUsers() { List <Usuarios> Usuarios = UsuariosHelper.GetAll(); bool TheresData = Usuarios.Count > 0; if (!TheresData) { throw new HttpResponseException(HttpStatusCode.NoContent); } return(Request.CreateResponse(HttpStatusCode.OK, Usuarios)); }
public void UnFollowUser() { Usuarios_Seguidos rel = new Usuarios_Seguidos { UserId = 1, UserFollowedId = 2 }; bool actual = UsuariosHelper.UnFollowUser(rel); bool expected = true; Assert.AreEqual(expected, actual); }
public HttpResponseMessage GetUserById(int id) { Usuarios user = UsuariosHelper.GetUsuarioByPrimaryKey(id); bool TheresData = user != null; if (!TheresData) { throw new HttpResponseException(HttpStatusCode.NoContent); } return(Request.CreateResponse(HttpStatusCode.OK, user)); }
private void actualizar() { try { this.user = new Usuarios(); this.user.Usuario = this.txtUsuario.Text; this.user.Clave = EncryptionHelper.Encrypt(this.txtClave.Text); if (this.chckbxActivo.Checked) { this.user.Activo = true; } else { this.user.Activo = false; } if (this.cmbRol.SelectedIndex == 0) { this.user.Rol = 1; } else if (this.cmbRol.SelectedIndex == 1) { this.user.Rol = 2; } else if (this.cmbRol.SelectedIndex == 2) { this.user.Rol = 3; } this.user.Nombre = this.txtNombre.Text; this.user.Apellido = this.txtApellido.Text; this.user.Correo = this.txtCorreo.Text; this.user.opc = 4; this.userHelper = new UsuariosHelper(user); this.bitacora = new Bitacora(); this.bitacora.Usuario = this.stsUsuario.Text; this.bitacora.Movimiento = "Actualizar"; this.bitacora.Detalle = "Se actualizo el usuario correctamente " + this.txtUsuario.Text; this.bitacora.opc = 5; this.bitH = new BitacoraHelper(bitacora); this.bitH.LogMovimientos(); this.userHelper.Actualizar(); MessageBox.Show("Datos del Usuario " + this.user.Usuario + " actualizados"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public HttpResponseMessage GetUserByUserName(string username) { Usuarios user = UsuariosHelper.GetUsuario(username); bool TheresData = user != null; if (!TheresData) { throw new HttpResponseException(HttpStatusCode.NoContent); } return(Request.CreateResponse(HttpStatusCode.OK, user)); }
public Usuario Obtener(int id) { var usuario = new Usuario(); try { usuario = new UsuariosHelper().Get(id); } catch (Exception ex) { throw new Exception(ex.Message); } return(usuario); }
private void CheckRolesAndSuperUser() { //UsuariosHelper.CheckRole("SuperAdmin"); //UsuariosHelper.CheckRole("Admin"); //UsuariosHelper.CheckRole("User"); //UsuariosHelper.CheckRole("Servicio"); //UsuariosHelper.CheckRole("Cliente"); //UsuariosHelper.CheckRole("CONSULTAS"); UsuariosHelper.CheckSuperUser(); //UsuariosHelper.CrearRoles("SuperAdmin"); //UsuariosHelper.CrearRoles("Admin"); //UsuariosHelper.CrearRoles("User"); //UsuariosHelper.CrearRoles("Servicio"); //UsuariosHelper.CrearRoles("Cliente"); //UsuariosHelper.CrearRoles("CONSULTAS"); //UsuariosHelper.CrearModulo("GENERAL"); //UsuariosHelper.CrearOperaciones("AGREGAR", 1); //UsuariosHelper.CrearOperaciones("EDITAR", 1); //UsuariosHelper.CrearOperaciones("ELIMINAR", 1); //UsuariosHelper.CrearOperaciones("DETALLE", 1); //UsuariosHelper.CrearOperaciones("CONSULTAS", 1); //UsuariosHelper.CrearOperaciones("CERRAR", 1); //UsuariosHelper.CrearOperaciones("CODIGOS", 1); //UsuariosHelper.CrearRolOperaciones(1, 1); //UsuariosHelper.CrearRolOperaciones(1, 2); //UsuariosHelper.CrearRolOperaciones(1, 3); //UsuariosHelper.CrearRolOperaciones(1, 4); //UsuariosHelper.CrearRolOperaciones(1, 5); //UsuariosHelper.CrearRolOperaciones(1, 6); //UsuariosHelper.CrearRolOperaciones(1, 7); //UsuariosHelper.CrearRolOperaciones(2, 1); //UsuariosHelper.CrearRolOperaciones(2, 2); //UsuariosHelper.CrearRolOperaciones(2, 3); //UsuariosHelper.CrearRolOperaciones(2, 4); //UsuariosHelper.CrearRolOperaciones(2, 5); //UsuariosHelper.CrearRolOperaciones(2, 6); //UsuariosHelper.CrearRolOperaciones(2, 7); //UsuariosHelper.CrearRolOperaciones(6, 4); //UsuariosHelper.CrearRolOperaciones(6, 5); //UsuariosHelper.CrearRolOperaciones(3, 1); //UsuariosHelper.CrearRolOperaciones(3, 2); //UsuariosHelper.CrearRolOperaciones(3, 4); //UsuariosHelper.CrearRolOperaciones(3, 5); //UsuariosHelper.CrearCategorias("EQUITY"); //UsuariosHelper.CrearCategorias("FRANQUICIAS"); //UsuariosHelper.CrearCategorias("EQUITY / FRANQUICIAS"); //UsuariosHelper.CrearCategorias("STOCK"); }
public HttpResponseMessage FollowUser([FromBody] Usuarios_Seguidos rel) { if (Usuarios_SeguidosHelper.UserIsFollowed(rel)) { throw new HttpResponseException(HttpStatusCode.Conflict); } bool result = UsuariosHelper.FollowUser(rel); if (!result) { throw new HttpResponseException(HttpStatusCode.InternalServerError); } return(Request.CreateResponse(HttpStatusCode.Created)); }
public ActionResult Delete(int id) { Usuario usuario = db.Usuarios.Where(x => x.UsuarioId == id).FirstOrDefault(); db.Usuarios.Remove(usuario); var response = DBHelper.SaveChanges(db); if (response.Succeeded) { UsuariosHelper.DeleteUser(usuario.NombreUsuario); return(Json(new { success = true, message = "USUARIO ELIMINADO" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = true, message = response.Message }, JsonRequestBehavior.AllowGet)); } }
//FUNCION AGREGAR NUEVO USUARIO private void guardar() { try { //AGREGAR NUEVO USUARIO this.user = new Usuarios(); this.user.Usuario = this.txtUsuario.Text; this.user.Clave = EncryptionHelper.Encrypt(this.txtClave.Text); if (this.chckbxActivo.Checked) { this.user.Activo = true; } else { this.user.Activo = false; } if (this.cmbRol.SelectedIndex == 0) { this.user.Rol = 1; } else if (this.cmbRol.SelectedIndex == 1) { this.user.Rol = 2; } else if (this.cmbRol.SelectedIndex == 2) { this.user.Rol = 3; } //this.user.Rol = int.Parse(this.cmbRol.Text); this.user.Nombre = this.stsUsuario.Text; this.user.Apellido = this.txtApellido.Text; this.user.Correo = this.txtCorreo.Text; this.user.opc = 2; this.userHelper = new UsuariosHelper(user); ///LOG PARA USUARIOS LogMovimientos(); this.userHelper.Guardar(); MessageBox.Show("Usuario " + this.user.Usuario + " Almacenado"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public async Task <ActionResult> ResetPassword(ResetPasswordViewModel model) { if (ModelState.IsValid) { var user = await UserManager.FindByNameAsync(model.Email); if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id))) { await UsuariosHelper.ChangePassword(user.Email, model.ConfirmPassword); var perfil = db.Usuarios.Where(u => u.NombreUsuario == model.Email).FirstOrDefault(); return(Json(new { success = true, message = "PASSWORD CAMBIADO CON ÉXITO" }, JsonRequestBehavior.AllowGet)); } } return(Json(new { success = true, message = "NO COINCIDE EL PASSWORD CON LA CONFIRMACION DEL PASSWORD, INTENTALO NUEVAMENTE" }, JsonRequestBehavior.AllowGet)); }
private void btnIngresar_Click(object sender, EventArgs e) { try { if (this.txtUsuarioLogin.Text != "" && this.txtClaveLogin.Text != "") { this.user = new Usuarios(); this.user.Usuario = this.txtUsuarioLogin.Text; this.user.Clave = EncryptionHelper.Encrypt(this.txtClaveLogin.Text); // this.user.Clave = this.txtClaveLogin.Text; this.user.opc = 5; this.userHelper = new UsuariosHelper(user); this.table = new DataTable(); this.table = this.userHelper.ValidarLogin(); if (table.Rows.Count > 0) { DataRow fila = table.Rows[0]; this.user.Usuario = fila["usuario"].ToString(); this.user.Rol = int.Parse(fila["rol"].ToString()); this.user.Nombre = fila["nombre"].ToString(); this.user.Apellido = fila["apellido"].ToString(); Principal inicio = new Principal(user); LogInicioSesion(); inicio.Show(); this.Hide(); } else { MessageBox.Show("Datos de inicio de sesión incorrectos o Usuario Inactivo"); } } else { MessageBox.Show("Campos vacios favor ingresar datos en ambos campos"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
protected void btningresar_Click(object sender, EventArgs e) { try { this.usuarios = new Usuarios(); this.usuarios.Nombre_usuario = this.txtnombreusuario.Text; this.usuarios.Clave = this.txtclave.Text; // uso de la opcion del proceso almacenado this.usuarios.Opc = 1; this.UsuariosHelper = new UsuariosHelper(usuarios); this.datos = new DataTable(); this.datos = this.UsuariosHelper.validarusuario(); if (datos.Rows.Count >= 0) { DataRow fila = datos.Rows[0]; Usuarios.setTipo(fila["tipo"].ToString()); if (fila["tipo"].ToString() == "administrador") { Usuarios.Setnombre(fila["Nombre"].ToString() + " " + fila["Apellido"].ToString()); Usuarios.setCedula(fila["Cedula"].ToString()); Usuarios.setCorreo(fila["Correo"].ToString()); Usuarios.setusuario(fila["Nombre_Usuario"].ToString()); Response.Redirect("inicioP.aspx"); } else if (fila["tipo"].ToString() == "cliente") { Usuarios.Setnombre(fila["Nombre"].ToString() + " " + fila["Apellido"].ToString()); Usuarios.setCedula(fila["Cedula"].ToString()); Usuarios.setCorreo(fila["Correo"].ToString()); Usuarios.setusuario(fila["Nombre_Usuario"].ToString()); Response.Redirect("Principal2.aspx"); } } } catch (Exception ex) { this.txtnombreusuario.Text = ex.Message; ScriptManager.RegisterStartupScript(this, typeof(Page), "mensajeError", "mensajeError('" + "" + "');", true); } }
private void eliminar() { try { this.table = (DataTable)this.dgvListar.DataSource; if (table == null) { MessageBox.Show("No hay Usuarios para eliminar"); } else { int indice = dgvListar.CurrentRow.Index; DataRow fila = table.Rows[indice]; this.user = new Usuarios(); this.user.Usuario = fila["usuario"].ToString(); this.user.opc = 3; this.userHelper = new UsuariosHelper(user); ///LOG PARA ELIMINAR /// this.bitacora = new Bitacora(); this.bitacora.Usuario = this.stsUsuario.Text; this.bitacora.Movimiento = "Eliminar"; this.bitacora.Detalle = "Se elimino el nuevo usuario " + fila["usuario"].ToString(); this.bitacora.opc = 5; this.bitH = new BitacoraHelper(bitacora); this.bitH.LogMovimientos(); this.userHelper.Eliminar(); MessageBox.Show("Usuario " + this.user.Usuario + " Eliminado"); listar(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
protected void btn_ingresar_Click(object sender, EventArgs e) { try { this.usuarios = new Usuarios(); this.usuarios.Nick_name = this.Txt_Usuario.Text; this.usuarios.Clave_usuario = this.Txt_clave.Text; this.usuarios.Opc = 1; this.usuariosHelper = new UsuariosHelper(usuarios); this.datos = new DataTable(); this.datos = this.usuariosHelper.validarusuario(); if (datos.Rows.Count >= 0) { DataRow fila = datos.Rows[0]; Response.Redirect("inicio.aspx"); } } catch (Exception) { ScriptManager.RegisterStartupScript(this, typeof(Page), "mensajeError", "mensajeError('" + "" + "');", true); } }
private void listar() { try { this.user = new Usuarios(); this.user.opc = 1; this.userHelper = new UsuariosHelper(user); this.table = new DataTable(); this.table = this.userHelper.Listar(); if (this.table.Rows.Count > 0) { this.dgvListar.DataSource = this.table; this.dgvListar.ReadOnly = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { var user = await UserManager.FindByNameAsync(model.Email); if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id))) { if (user == null) { return(Json(new { success = true, message = "NO EXISTE EL USUARIO CAPTURADO" }, JsonRequestBehavior.AllowGet)); } else { await UsuariosHelper.PasswordRecovery(user.Email); return(Json(new { success = true, message = "PASSWORD REESTABLECIDO, REVISA TU MAIL" }, JsonRequestBehavior.AllowGet)); //return RedirectToAction("Login"); } } } return(View(model)); }
protected void btn_agregar_usuario_Click(object sender, EventArgs e) { if (this.txt_clave1.Text == this.txt_clave2.Text) { this.usu = new Usuarios(); this.usu.Cedula_usuario = this.txt_cedula.Text; this.usu.Nombre_usuario = this.txt_nombre.Text; this.usu.Apellido1 = this.txt_apellido1.Text; this.usu.Apellido2 = this.txt_apellido2.Text; this.usu.Nick_name = this.txt_nickname.Text; this.usu.Correo_electronico = this.txt_correo.Text; this.usu.Clave_usuario = this.txt_clave2.Text; this.usu.Rol = "administrador"; this.usu.Estado = "Activo"; this.usu.Opc = 1; this.usuariosHelper = new UsuariosHelper(usu); this.usuariosHelper.Agregar_Usuarios(); ScriptManager.RegisterStartupScript(this, typeof(Page), "mensajeDeconfirmacion", "mensajeDeconfirmacion('" + "" + "');", true); } else { this.txt_clave2.Text = "las contraseñas no coinciden por favor verifique"; } }