示例#1
0
        public string ConsultarImagenUsuarioPerfil(SegUsuarios segUsuario)
        {
            StringBuilder htmlGeneric = new StringBuilder();

            htmlGeneric.Append("<img src='" + segUsuario.foto + "' class='img-responsive img-rounded img-thumbnail' alt='Responsive image'>");
            return(htmlGeneric.ToString());
        }
示例#2
0
        public async Task <IActionResult> Edit(long id, [Bind("Idsus,Login,Password,Nombres,Apellidos,Correo,Vigente,Idcde,Idobr,Tablet,Apiestado,Apitransaccion,Usucre,Feccre,Usumod,Fecmod")] SegUsuarios segUsuarios)
        {
            if (id != segUsuarios.Idsus)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    segUsuarios.Usumod         = this.GetLogin();
                    segUsuarios.Apitransaccion = "MODIFICAR";
                    _context.Update(segUsuarios);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SegUsuariosExists(segUsuarios.Idsus))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                catch (Exception exp)
                {
                    if (exp.InnerException is NpgsqlException)
                    {
                        ViewBag.ErrorDb = exp.InnerException.Message;
                    }
                    else
                    {
                        ModelState.AddModelError("", exp.Message);
                    }
                    ViewData["Idcde"] =
                        new SelectList(_context.CatDepartamentos,
                                       CatDepartamentos.Fields.Idcde.ToString(),
                                       CatDepartamentos.Fields.Idcde.ToString());
                    ViewData["Idobr"] =
                        new SelectList(_context.OpeBrigadas,
                                       OpeBrigadas.Fields.Idobr.ToString(),
                                       OpeBrigadas.Fields.Codigo.ToString());
                    return(View(segUsuarios));
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Idcde"] = new SelectList(_context.CatDepartamentos,
                                               CatDepartamentos.Fields.Idcde.ToString(),
                                               CatDepartamentos.Fields.Idcde.ToString(),
                                               segUsuarios.Idcde);
            ViewData["Idobr"] = new SelectList(_context.OpeBrigadas,
                                               OpeBrigadas.Fields.Idobr.ToString(),
                                               OpeBrigadas.Fields.Codigo.ToString(),
                                               segUsuarios.Idobr);
            return(View(segUsuarios));
        }
示例#3
0
        protected void setVisibleDatosPersonaPerfil(SegUsuarios segusuario)
        {
            string nombreCompleto = segusuario.strNombre + " " + segusuario.strAPaterno + " " + segusuario.strAMaterno;

            this.etAlumno.Text           = nombreCompleto;
            this.txtNombre.Text          = segusuario.strNombre;
            this.txtApellidoPaterno.Text = segusuario.strAPaterno;
            this.txtApellidoMaterno.Text = segusuario.strAMaterno;
            this.txtEmail.Text           = segusuario.email;
            this.txtNumeroMatricula.Text = segusuario.strMatricula;
            this.txtSemestreActual.Text  = segusuario.strSemestreActual;
        }
示例#4
0
 protected void setVisibleDatosPerfil(SegUsuarios segusuario)
 {
     if (segusuario == null)
     {
         this.ImgPerfilUsuario.ImageUrl = "~/imagenes/anonimo.jpg";
         //this.userAlumno.ImageUrl = "~/imagenes/invitado.jpg";
     }
     else
     {
         this.ImgPerfilUsuario.ImageUrl = "/Handler/vizualizarFoto.ashx?id=" + segusuario.id;
         //this.userAlumno.ImageUrl = "/Handler/vizualizarFoto.ashx?id=" + segusuario.id;
         //this.setVisibleDatosPersonaPerfil(segusuario);
     }
 }
示例#5
0
        public SegUsuarios GetUsuarioById(int id)
        {
            SegUsuarios segusuario = null;

            try
            {
                segusuario = contexto.SegUsuarios.Where(p => p.id == id).FirstOrDefault <SegUsuarios>();
            }
            catch (Exception ex)
            {
                string mensajeErr = ex.Message;
            }
            return(segusuario);
        }
示例#6
0
        public SegUsuarios GetUsuarioByNombreUsuario(string nombreUsuario)
        {
            SegUsuarios segusuario = null;

            try
            {
                segusuario = contexto.SegUsuarios.Where(p => p.strUsuario == nombreUsuario).FirstOrDefault <SegUsuarios>();
            }
            catch (Exception ex)
            {
                string mensajeErr = ex.Message;
            }
            return(segusuario);
        }
示例#7
0
        /// <summary>
        /// este metodo se encarga de insertar  en la base de datos
        /// </summary>
        /// <param name="segUsaurio">recibe un segusaurio</param>
        /// <returns>regresa un valor  booleano</returns>
        public bool InsertarSegUsuario(SegUsuarios segUsuario)
        {
            bool respuesta = false;

            try
            {
                contexto.SegUsuarios.Add(segUsuario);
                contexto.SaveChanges();
                respuesta = true;
            }
            catch (Exception ex)
            {
                string mensajeErr = ex.Message;
            }
            return(respuesta);
        }
示例#8
0
        protected SegUsuarios GetDataViewSegUsuario(int idCarrera)
        {
            SegUsuarios segUsuario = new SegUsuarios();

            segUsuario.strUsuario  = txtNombreUsuario.Text.ToLower();
            segUsuario.strPassword = txtPassword.Text.Trim().ToLower();
            segUsuario.strNombre   = txtNombre.Text.ToLower();
            segUsuario.strAPaterno = txtApellidoPaterno.Text.ToLower();
            segUsuario.strAMaterno = txtApellidoMaterno.Text.ToLower();
            segUsuario.strTelefono = txtTelefonoCelular.Text.ToLower();
            //cargamos la foto para poderla insertar en la base de datos
            segUsuario.foto            = (byte[])Session["foto"];
            segUsuario.email           = txtEmail.Text.ToLower();
            segUsuario.strPlanEstudios = txtPlanEstudios.Text.ToLower();
            //establecemos el identificador del alumno a traves del perfil
            segUsuario.idSegPerfil = int.Parse(Recursos.ID_PERFIL_ALUMNO);
            //obtenemos el id de la carrera
            segUsuario.idCarrera = idCarrera;

            //creamos la entidad credito
            Creditos credito = new Creditos();

            //llenamos nuestra entidad
            credito.creditosAprobados = int.Parse(this.txtCreditosAprobados.Text.ToLower());
            credito.creditosPorCursar = int.Parse(this.txtCreditosPorCursar.Text.ToLower());
            credito.creditosTotales   = int.Parse(this.txtCreditosTotales.Text.ToLower());

            //insertamos  la entidad credito en la entidad principal
            //recordando que creditos es una lista, a esta lista le asignamos un elemento de la entidad credito
            segUsuario.Creditos.Add(credito);

            //creamos la entidad del tipo Asignaturas
            Asignaturas asignatura = new Asignaturas();

            asignatura.asignaturasTotales    = int.Parse(this.txtAsignaturasTotales.Text.Trim());
            asignatura.asignaturasAprobadas  = int.Parse(this.txtAsignaturasAprobadas.Text.Trim());
            asignatura.asignaturasCursar     = int.Parse(this.txtAsignaturasCursadas.Text.Trim());
            asignatura.asignaturasReprobadas = int.Parse(this.txtAsignaturasReprobadas.Text.Trim());
            asignatura.asignaturasRepeticion = int.Parse(this.txtAsignaturasRepetición.Text.Trim());

            //relacionamos  la asignatura creada a la entidad principal
            //recuerda que asignatura es una lista pero solo almacenamos una sola entidad
            segUsuario.Asignaturas.Add(asignatura);

            return(segUsuario);///regresamos la entidad  a insertar ya precargada
        }
示例#9
0
        public CatCarrera GetConsultarCatCarreraPorUsuario(int idUsuario)
        {
            CatCarrera catCarrera = null;

            try
            {
                SegUsuarios usuarios = contexto.SegUsuarios.
                                       Where(p => p.id == idUsuario).FirstOrDefault <SegUsuarios>();
                catCarrera = contexto.CatCarrera.
                             Where(p => p.id == usuarios.idCarrera).FirstOrDefault <CatCarrera>();
            }
            catch (Exception ex)
            {
                string errorMensaje = ex.Message;
            }
            return(catCarrera);
        }
        protected void btnGuardar_Click(object sender, EventArgs e)
        {
            SegUsuarios usuario = new SegUsuarios()
            {
                PrimerNombre               = txtPrimerNombre.Text.Trim(),
                SegundoNombre              = txtSegundoNombre.Text.Trim(),
                PrimerApellido             = txtPrimerApellido.Text.Trim(),
                SegundoApellido            = txtSegundoApellido.Text.Trim(),
                Username                   = txtUsername.Text.Trim(),
                Password                   = txtPassword.Text.Trim(),
                FechaActualizacionRegistro = DateTime.Now,
                FechaCreacionRegistro      = DateTime.Now
            };

            ProcesoNegocio pn = new ProcesoNegocio();
            int            a  = pn.InsertarUsuario(usuario);
        }
示例#11
0
        /// <summary>
        /// este metodo busca a un usuario de acuerdo a un nombre de  usuario y un password.
        /// </summary>
        /// <param name="nombre">el nombre del usuario</param>
        /// <param name="password">el password del usuario</param>
        /// <returns>regresa un segusuario</returns>
        public SegUsuarios GetUsuarioLogin(string nombre, string password)
        {
            SegUsuarios segusuario = null;

            try
            {
                Expression <Func <SegUsuarios, bool> > predicado = p => p.strNombre == nombre &&
                                                                   p.strPassword == password;
                segusuario = contexto.SegUsuarios.
                             Where(predicado.Compile()).FirstOrDefault <SegUsuarios>();
            }
            catch (Exception ex)
            {
                string mensajeErr = ex.Message;
            }
            return(segusuario);
        }
示例#12
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         CtrlSession ctrlSession = new CtrlSession();
         ctrlSession.validaSession(this);
         sesionManager = (SessionManager)this.Session[Recursos.MANAGER];
         if (sesionManager.Parametros[Recursos.USER] != null)
         {
             SegUsuarios segUser    = (SegUsuarios)sesionManager.Parametros[Recursos.USER];
             SegUsuarios segusuario = segUsuarioRepository.GetUsuarioById(segUser.id);
             sesionManager.Parametros[Recursos.USER] = segusuario;
             Session[Recursos.MANAGER] = sesionManager;
             this.setVisibleDatosPerfil(segusuario);
             this.setVisibleDatosPersonaPerfil(segusuario);
         }
     }
 }
示例#13
0
        protected void BtnLogin_Click(object sender, EventArgs e)
        {
            string nombre   = txtMailUsuario.Text;                                     //obtenemos el nombre del usuario de la vista
            string password = txtPassword.Text;                                        //obtenemos el password del usuario

            this.segUsuarios = segUsuarioRepository.GetUsuarioLogin(nombre, password); //vamos a validar al usuario

            //se valida que el usuario contenga el perfil del alumno
            if (this.segUsuarios != null &&
                this.segUsuarios.SegPerfil.strValor.Equals(Recursos.PERFIL_ALUMNO))
            {
                this.sesionManager           = new SessionManager();
                this.sesionManager.IdUsuario = this.segUsuarios.id;
                this.sesionManager.Parametros[Recursos.USER] = this.segUsuarios;
                Session[Recursos.MANAGER] = sesionManager;
                this.Response.Redirect("Alumno/perfil.aspx", true);
            }
            else
            {
            }
        }
示例#14
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CtrlSession ctrlSession = new CtrlSession(); //utilizamos la controladora de la sesion
                ctrlSession.validaSession(this);             //validamos la sesion dentro del sistema
                sesionManager = (SessionManager)this.Session[Recursos.MANAGER];
                if (sesionManager.Parametros[Recursos.USER] != null)
                {
                    SegUsuarios segUser    = (SegUsuarios)sesionManager.Parametros[Recursos.USER]; ///traemos al objeto segUsuario de la sesion
                    SegUsuarios segUsuario = segUsuarioRepository.GetUsuarioById(segUser.id);      //consultamos que el usuario si esta en base de datos
                    //establezco los valores validados en la sesion
                    sesionManager.Parametros[Recursos.USER] = segUsuario;
                    Session[Recursos.MANAGER] = sesionManager;

                    //llamamos a el metodo que se encarga de poner los datos en la pantalla
                    this.setVisibleDatosPersonaPerfil(segUsuario);
                    this.setVisibleDatosPerfil(segUsuario);
                }
            }
        }
示例#15
0
 public Stream MostrarImagen(int _idUsuario)
 {
     try
     {
         SegUsuarios             segUsuario = segUsuarioRepository.GetUsuarioById(_idUsuario);
         System.Data.Linq.Binary fotoData   = null;
         fotoData = (Binary)segUsuario.foto;
         if (fotoData != null)
         {
             byte[] arreglo = fotoData.ToArray();
             return(new MemoryStream(arreglo));
         }
         else
         {
             return(null);
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
示例#16
0
        public bool actualizarUsuario(SegUsuarios segUsuario)
        {
            bool respuesta = false;

            try
            {
                SegUsuarios usuario = contexto.SegUsuarios.Where(p => p.id == segUsuario.id).FirstOrDefault <SegUsuarios>();
                usuario.strMatricula      = segUsuario.strMatricula;
                usuario.strSemestreActual = segUsuario.strSemestreActual;
                contexto.SegUsuarios.Attach(segUsuario);
                contexto.Entry(segUsuario).State = System.Data.Entity.EntityState.Modified;
                contexto.SaveChanges();

                respuesta = true;
            }
            catch (Exception ex)
            {
                respuesta = false;
                string mensajeError = ex.Message;
            }
            return(respuesta);
        }
示例#17
0
        public SegUsuarios GetUsuarioByMatricula(string matricula)
        {
            SegUsuarios _segUsuarios = null;
            CatCarrera  _catCarrera  = null;

            try
            {
                Expression <Func <SegUsuarios, bool> > predicate = p => p.strMatricula.Equals(matricula);
                _segUsuarios = contexto.SegUsuarios.Where(predicate.Compile()).FirstOrDefault <SegUsuarios>();
                if (_segUsuarios != null)
                {
                    int id = (int)_segUsuarios.idCarrera;
                    Expression <Func <CatCarrera, bool> > predicate1 = p => p.id.Equals(id);
                    _catCarrera             = contexto.CatCarrera.Where(predicate1.Compile()).FirstOrDefault <CatCarrera>();
                    _segUsuarios.CatCarrera = _catCarrera;
                }
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
            }
            return(_segUsuarios);
        }
        public async Task <IActionResult> Login(SegUsuarios user, string strReturnUrl)
        {
            ViewData["ReturnUrl"] = strReturnUrl;
            if (ModelState.IsValid)
            {
                const string badUserNameOrPasswordMessage = "Usuario o contraseña incorrectos.";
                const string badUserCreation = "El Usuario no tiene un Rol activo";
                if (user == null)
                {
                    ModelState.AddModelError("", badUserNameOrPasswordMessage);
                    return(View());
                }

                const string incompleteInformation = "Debe especificar un usuario y contraseña para continuar.";
                if (user.Login == "" || user.Password == "")
                {
                    ModelState.AddModelError("", incompleteInformation);
                    return(View());
                }

                var obj = _context.SegUsuarios.SingleOrDefault(m => m.Login == user.Login);
                if (obj == null)
                {
                    ModelState.AddModelError("", badUserNameOrPasswordMessage);
                    return(View());
                }

                if (!CFunciones.GenerarMd5(user.Password).ToUpper().Equals(obj.Password.ToUpper()))
                {
                    ModelState.AddModelError("", badUserNameOrPasswordMessage);
                    return(View());
                }

                var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme);
                identity.AddClaim(new Claim(ClaimTypes.Name, obj.Login));
                identity.AddClaim(new Claim(ClaimTypes.GivenName, obj.Nombres + " " + obj.Apellidos));

                //Para el Rol
                var objRol = _context.SegUsuarios
                             .Join(_context.SegUsuariosRestriccion, sus => sus.Idsus, sur => sur.Idsus, (sus, sur) => new { sus, sur })
                             .Join(_context.SegRoles, sussur => sussur.sur.Idsro, sro => sro.Idsro, (sussur, sro) => new { sussur, sro })
                             .Where(t => t.sussur.sur.Rolactivo == 1)
                             .Where(t => string.Equals(t.sussur.sus.Login, obj.Login, StringComparison.CurrentCultureIgnoreCase))
                             .Select(arg => arg).SingleOrDefault();
                if (objRol == null)
                {
                    identity.AddClaim(new Claim(ClaimTypes.Role, string.Empty));
                    identity.AddClaim(new Claim(ClaimTypes.GroupSid, string.Empty));
                    HttpContext.Session.SetString("currentApp", string.Empty);
                    ModelState.AddModelError("", badUserCreation);
                    return(View());
                }
                identity.AddClaim(new Claim(ClaimTypes.Role, objRol.sro.Idsro.ToString()));
                identity.AddClaim(new Claim(ClaimTypes.GroupSid, objRol.sussur.sur.Idopy.ToString()));
                identity.AddClaim(new Claim(ClaimTypes.PrimarySid, objRol.sussur.sur.Idcde.ToString()));
                var objApp = CMenus.GetAplicaciones(_context, objRol.sro.Idsro).OrderBy(x => x.Nombre).First();

                HttpContext.Session.SetString("currentApp", objApp == null? string.Empty : objApp.Sigla);

                await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity));

                if (strReturnUrl == null)
                {
                    if (TempData["returnUrl"] != null)
                    {
                        return(Redirect(TempData["returnUrl"].ToString()));
                    }
                }

                return(RedirectToAction(nameof(DashboardController.Index), "Dashboard"));
            }

            // If we got this far, something failed, redisplay form
            return(View());
        }