Ejemplo n.º 1
0
        public void CambiarEstado(int id)
        {
            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    var oferta = bbdd.OfertaEmpleo.Where(o => o.id == id).SingleOrDefault();
                    oferta.Abierta = oferta.Abierta ? false : true;
                    bbdd.Entry(oferta).Property(o => o.Abierta).IsModified = true;
                    bbdd.SaveChanges();

                    //actualizar InscritosHistorial
                    int       estado    = oferta.Abierta ? 35 : 31;
                    var       lista     = new List <Inscritos>();
                    Inscritos inscritos = new Inscritos();
                    lista = inscritos.GetInscritos(id);
                    InscritosHistorial historial = new InscritosHistorial();
                    foreach (var item in lista)
                    {
                        historial.SetHistorial(item.Usuario_id_D, item.Oferta_id, estado);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        public int SetNuevoUser()
        {
            int result = -1;

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    // Email no puede existir en la bbdd
                    var usuario = bbdd.Usuario.Where(u => u.Email == this.Email);
                    if (usuario.Count() > 0)
                    {
                        result = 0;
                    }
                    else
                    {
                        //dar de alta usuario nuevo
                        this.Password          = HashHelper.MD5(this.PassNuevo);
                        this.PassActual        = this.Password; //para que no de error de validacion
                        bbdd.Entry(this).State = EntityState.Added;
                        bbdd.SaveChanges();
                        result = 1;
                    }
                }
                return(result);
            }
            catch (Exception)
            {
                return(result);
            }
        }
Ejemplo n.º 3
0
        public bool GuardarUsuario()
        {
            bool result = false;

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    var usuario = bbdd.Entry(this);
                    usuario.State = EntityState.Modified;

                    //El campo password decimos que no se modifica ya que no se lo pasamos.
                    usuario.Property(u => u.Password).IsModified = false;
                    usuario.Property(u => u.Rol_id).IsModified   = false;

                    //Para que no de error al grabar puesto que no pasamos Password
                    bbdd.Configuration.ValidateOnSaveEnabled = false;
                    bbdd.SaveChanges();

                    HttpContext.Current.Session["nombre"] = this.Nombre;
                    result = true;
                }
            }
            catch (Exception)
            {
                return(result);
            }

            return(result);
        }
Ejemplo n.º 4
0
        public OfertaEmpleo GetOferta(int id)
        {
            int usuario_id = SesionHelper.GetUser();
            var oferta     = new OfertaEmpleo();

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    oferta = bbdd.OfertaEmpleo.Where(oe => oe.id == id).Where(oe => oe.Usuario_id == usuario_id).SingleOrDefault();
                    //registrar la ultma vez que se entra a ver la oferta por parte de la empresa
                    if (oferta != null)
                    {
                        oferta.FechaGestion      = DateTime.Now;
                        bbdd.Entry(oferta).State = EntityState.Modified;
                        bbdd.SaveChanges();
                    }
                }
                return(oferta);
            }
            catch (Exception)
            {
                return(oferta);
            }
        }
Ejemplo n.º 5
0
        public bool SetOferta()
        {
            bool result = false;

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    if (this.id == 0)
                    {
                        bbdd.Entry(this).State = EntityState.Added;
                    }
                    else
                    {
                        var oe = bbdd.Entry(this);
                        bbdd.Entry(this).State = EntityState.Modified;
                    }
                    bbdd.SaveChanges();
                    result = true;
                }
                return(result);
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException ex)
            {
                return(false);
            }
        }
Ejemplo n.º 6
0
        //LOGICA DE NEGOCIO

        public List <Mensaje> ListaMensajes(int usuario_id, int estado_id)
        {
            var lista = new List <Mensaje>();

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    var consulta = from m in bbdd.Mensaje.Where(m => m.Usuario_id == usuario_id)
                                   .Where(m => m.Estado_id == estado_id)
                                   .OrderByDescending(m => m.Fecha)
                                   select m;

                    foreach (var registro in consulta)
                    {
                        lista.Add(registro);
                    }
                }
            }
            catch (Exception ex)
            {
                return(lista);
            }
            return(lista);
        }
Ejemplo n.º 7
0
        public bool GuardarExperiencia()
        {
            bool result = false;

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    if (this.id == 0)//nuevo regitro
                    {
                        bbdd.Entry(this).State = EntityState.Added;
                        bbdd.SaveChanges();
                        result = true;
                    }
                    else //modificacion registro
                    {
                        bbdd.Entry(this).State = EntityState.Modified;
                        bbdd.SaveChanges();
                        result = true;
                    }
                }
            }
            catch (Exception ex)
            {
                return(result);
            }
            return(result);
        }
Ejemplo n.º 8
0
        //LOGICA NEGOCIO
        public List <Idiomas> GetIdiomasDisponibles()
        {
            int usuario_id = SesionHelper.GetUser();
            var lista      = new List <Idiomas>();

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    lista = (from ii in bbdd.Idiomas
                             .Except(
                                 from ii in bbdd.Idiomas
                                 join i in bbdd.Idioma
                                 on ii.id equals i.Idiomas_id
                                 where i.Usuario_id == usuario_id
                                 select(ii)
                                 )
                             select(ii)).ToList();
                    return(lista);
                }
            }
            catch (Exception ex)
            {
                return(lista);
            }
        }
Ejemplo n.º 9
0
        public int CambiarPassword(int id, string actualPass, string nuevoPass)
        {
            int result = -1;

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    var usuario = bbdd.Usuario.Where(u => u.id == id).SingleOrDefault();
                    actualPass = HashHelper.MD5(actualPass);
                    if (actualPass == usuario.Password)
                    {
                        usuario.Password = HashHelper.MD5(nuevoPass);
                        bbdd.Configuration.ValidateOnSaveEnabled = false;
                        bbdd.SaveChanges();
                        result = 1;
                    }
                    else
                    {
                        result = 0;
                    }
                }
            }
            catch (Exception ex)
            {
                return(result);
            }
            return(result);
        }
Ejemplo n.º 10
0
        //LOGICA NEGOCIO PARA ROL USUARIO
        public List <Inscritos> GetMisCandidaturas()
        {
            var lista      = new List <Inscritos>();
            int usuario_id = SesionHelper.GetUser();

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    lista = bbdd.Inscritos
                            .Include("OfertaEmpleo")
                            .Include("OfertaEmpleo.Inscritos")
                            .Include("OfertaEmpleo.Categoria")
                            .Include("Usuario1")
                            .Include("Estado")
                            .Where(c => c.Usuario_id_D == usuario_id)
                            .OrderByDescending(c => c.Fecha).ToList();
                }
                return(lista);
            }
            catch (Exception)
            {
                return(lista);
            }
        }
Ejemplo n.º 11
0
        public bool Guardar()
        {
            bool result = false;

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    if (this.id == 0)
                    {
                        bbdd.Entry(this).State = EntityState.Added;
                    }
                    else
                    {
                        bbdd.Entry(this).State = EntityState.Modified;
                    }
                    bbdd.SaveChanges();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                return(result);
            }
            return(result);
        }
Ejemplo n.º 12
0
        // ///////LOGICA DE NEGOCIO
        public Usuario Acceder(string email, string password)
        {
            Usuario usuario = (Usuario)null;

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    //convertir password a md5
                    password = HashHelper.MD5(password);
                    usuario  = bbdd.Usuario.Where(u => u.Email == email)
                               .Where(u => u.Password == password).SingleOrDefault();
                    if (usuario != null)
                    {
                        SesionHelper.AddUserASesion(usuario.id.ToString(),
                                                    usuario.Nombre, usuario.Foto, Convert.ToInt16(usuario.Rol_id));

                        Mensaje alerta = new Mensaje();
                        HttpContext.Current.Session.Add("MensajesSinLeer", alerta.GetSinLeer(usuario.id));
                    }
                }
            }
            catch (Exception ex)
            {
                return(usuario);
            }
            return(usuario);
        }
Ejemplo n.º 13
0
        //LOGICA NEGOCIO ROL EMPRESA
        public List <Inscritos> GetInscritos(int oferta_id, int estado = 0)
        {
            var lista      = new List <Inscritos>();
            var empresa_id = SesionHelper.GetUser();

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    lista = bbdd.Inscritos.Include("Usuario")
                            .Where(i => i.Oferta_id == oferta_id)
                            .Where(i => i.Usuario_id_E == empresa_id)
                            .ToList();
                    if (estado > 0)
                    {
                        lista = lista.Where(i => i.estado_id == estado).ToList();
                    }
                }
                return(lista);
            }
            catch (Exception)
            {
                return(lista);
            }
        }
Ejemplo n.º 14
0
        public bool GuardarFoto(int id, string nuevaFoto)
        {
            bool result = false;

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    var usuario = bbdd.Usuario.Where(u => u.id == id).SingleOrDefault();

                    string fotoAntigua = usuario.Foto;
                    usuario.Foto = nuevaFoto;

                    bbdd.Entry(usuario).State = EntityState.Modified;
                    bbdd.Configuration.ValidateOnSaveEnabled = false;
                    bbdd.SaveChanges();
                    result = true;
                    SubirArchivos.BorrarFotoAntigua(id, fotoAntigua);
                    HttpContext.Current.Session["foto"] = nuevaFoto;
                }
            }
            catch (Exception ex)
            {
                return(result);
            }
            return(result);
        }
Ejemplo n.º 15
0
        public Mensaje LeerMensaje(int id)
        {
            Mensaje mensaje    = null;
            int     usuario_id = SesionHelper.GetUser();

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    mensaje = bbdd.Mensaje
                              .Where(m => m.id == id)
                              .Where(m => m.Usuario_id == usuario_id)
                              .SingleOrDefault();
                    // si mensaje es null, salta un excepcion y devuelve null  y es evaluada por el controlador
                    //Origen.... Intento de leer mensajes de otros usuarios.
                    if (mensaje.Estado_id == 1)
                    {
                        //marcar como leido
                        mensaje.Estado_id = 2;
                        bbdd.Entry(mensaje).Property(m => m.Estado_id).IsModified = true;
                        bbdd.SaveChanges();
                    }

                    return(mensaje);
                }
            }
            catch (Exception)
            {
                return(mensaje);
            }
        }
Ejemplo n.º 16
0
 public Conocimiento ObtenerConocimiento(int id)
 {
     try
     {
         using (var bbdd = new ProyectoContexto())
         {
             var Conocimiento = bbdd.Conocimiento.Where(h => h.id == id).SingleOrDefault();
             return(Conocimiento);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 17
0
 public Experiencia ObtenerExperiencia(int id)
 {
     try
     {
         using (var bbdd = new ProyectoContexto())
         {
             var experiencia = bbdd.Experiencia.Where(e => e.id == id).SingleOrDefault();
             return(experiencia);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 18
0
        // LOGICA DE NEGOCIO FRONT-END

        public List <OfertaEmpleo> GetOfertasAbiertas(Filtro filtro = null)
        {
            var lista = new List <OfertaEmpleo>();

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    lista = bbdd.OfertaEmpleo
                            .Include("Usuario")
                            .Include("Inscritos")
                            .Include("Categoria")
                            .Where(oe => oe.Abierta == true)
                            .OrderByDescending(oe => oe.Fecha)
                            .ToList();

                    //filtros
                    if (filtro.porTitulo != null)
                    {
                        lista = lista.Where(oe => oe.Nombre.ToLower().Contains(filtro.porTitulo.ToLower().Trim())).ToList();
                    }
                    if (filtro.porFecha > 0)
                    {
                        lista = lista.Where(oe => oe.Fecha >= DateTime.Today.AddDays(-filtro.porFecha)).ToList();
                    }
                    if (filtro.porCiudad != null)
                    {
                        lista = lista.Where(oe => oe.Localidad == filtro.porCiudad).ToList();
                    }
                    if (filtro.porCategoria > 0)
                    {
                        lista = lista.Where(oe => oe.Categoria_id == filtro.porCategoria).ToList();
                    }
                    if (filtro.Salario > 0)
                    {
                        lista = lista.Where(oe => oe.Salario >= filtro.Salario).ToList();
                        lista = lista.Where(oe => oe.Pago == filtro.porNombre).ToList();
                    }
                    return(lista);
                }
            }
            catch (Exception)
            {
                return(lista);
            }
        }
Ejemplo n.º 19
0
        // LOGICA DE NEGOCIO
        public List <Categoria> GetListado()
        {
            var lista = new List <Categoria>();

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    lista = bbdd.Categoria.ToList();
                }
                return(lista);
            }
            catch (Exception ex)
            {
                return(lista);
            }
        }
Ejemplo n.º 20
0
        public Idioma GetIdioma(int id, int usuario_id)
        {
            Idioma idioma = null;

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    idioma = bbdd.Idioma.Include("Idiomas").Where(i => i.id == id).Where(i => i.Usuario_id == usuario_id).SingleOrDefault();
                }
            }
            catch (Exception)
            {
                return(idioma);
            }
            return(idioma);
        }
Ejemplo n.º 21
0
        //LOGICA DE NEGOCIO
        public List <Idioma> GetIdiomas(int usuario_id)
        {
            var idiomas = new List <Idioma>();

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    idiomas = bbdd.Idioma.Include("Idiomas").Where(i => i.Usuario_id == usuario_id).ToList();
                }
            }
            catch (Exception)
            {
                return(idiomas);
            }
            return(idiomas);
        }
Ejemplo n.º 22
0
        public List <Estado> GetEstadoInscrito()
        {
            var lista = new List <Estado>();

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    lista = bbdd.Estado.Where(e => e.Relacion == "inscrito").ToList();
                }
                return(lista);
            }
            catch (Exception)
            {
                return(lista);
            }
        }
Ejemplo n.º 23
0
        //LOGICA DE NEGOCIO

        public List <Estado> GetNiveles()
        {
            var lista = new List <Estado>();

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    lista = bbdd.Estado.Where(e => e.Relacion.Equals("idiomas")).ToList();
                    return(lista);
                }
            }
            catch (Exception)
            {
                return(lista);
            }
        }
Ejemplo n.º 24
0
        public Usuario GetDatosPersonales(int id)
        {
            Usuario usuario = null;

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    usuario = bbdd.Usuario.Where(u => u.id == id).SingleOrDefault();
                }
                return(usuario);
            }
            catch (Exception ex)
            {
                return(usuario);
            }
        }
Ejemplo n.º 25
0
        // //////   lOGICA DE NEGOCIO
        public List <Adjuntos> Listado(int usuario_id)
        {
            var lista = new List <Adjuntos>();

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    lista = bbdd.Adjuntos.Where(a => a.Usuario_id == usuario_id).ToList();
                    return(lista);
                }
            }
            catch (Exception ex)
            {
                return(lista);
            }
        }
Ejemplo n.º 26
0
        public int GetSinLeer(int usuario_id)
        {
            int result = 0;

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    result = bbdd.Mensaje.Where(m => m.Usuario_id == usuario_id)
                             .Where(m => m.Estado_id == 1).Count();
                }
            }
            catch (Exception)
            {
                return(result);
            }
            return(result);
        }
Ejemplo n.º 27
0
        public Inscritos GetInscripcion(Int64 numIscripcion)
        {
            Inscritos inscrito = null;

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    inscrito = bbdd.Inscritos.Include("Usuario")
                               .Where(i => i.NumInscripcion == numIscripcion).SingleOrDefault();
                }
                return(inscrito);
            }
            catch (Exception)
            {
                return(inscrito);
            }
        }
Ejemplo n.º 28
0
        public Usuario UsuarioActivo()
        {
            Usuario activo = null;

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    int id = SesionHelper.GetUser();
                    activo = bbdd.Usuario.Where(u => u.id == id).SingleOrDefault();
                }
            }
            catch (Exception)
            {
                return(activo);
            }
            return(activo);
        }
Ejemplo n.º 29
0
        public List <Conocimiento> ListaConocimientos(int usuario_id, Filtro filtro)
        {
            var lista = new List <Conocimiento>();

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    var consulta = from h in bbdd.Conocimiento
                                   .Where(h => h.Usuario_id == usuario_id)
                                   select h;
                    if (filtro.porNombre != null)
                    {
                        consulta = consulta.Where(h => h.Nombre.Contains(filtro.porNombre));
                    }
                    if (filtro.nombreOrderBy == "Desc")
                    {
                        consulta = consulta.OrderByDescending(h => h.Nombre);
                    }
                    if (filtro.nombreOrderBy == "Asc")
                    {
                        consulta = consulta.OrderBy(h => h.Nombre);
                    }
                    if (filtro.tituloOrderBy == "Desc")
                    {
                        consulta = consulta.OrderByDescending(h => h.Nivel);
                    }
                    if (filtro.tituloOrderBy == "Asc")
                    {
                        consulta = consulta.OrderBy(h => h.Nivel);
                    }

                    foreach (var registro in consulta)
                    {
                        lista.Add(registro);
                    }
                }
            }
            catch (Exception)
            {
                return(lista);;
            }
            return(lista);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Inscribir un Candidato a una oferta
        /// </summary>
        /// <returns>True si se ha podido inscribir, false si no se ha podido inscribirse</returns>
        public bool SetMiInscripcion()
        {
            bool result = false;

            try
            {
                using (var bbdd = new ProyectoContexto())
                {
                    bbdd.Entry(this).State = EntityState.Added;
                    bbdd.SaveChanges();
                    result = true;
                }
                return(result);
            }
            catch (Exception ex)
            {
                return(result);
            }
        }