Esempio n. 1
0
        public void Guardar(HttpPostedFileBase file, string extensionAntigua)
        {
            try
            {
                using (var db = new Model_Sistema())
                {
                    var doc = db.Entry(this);

                    if (this.documento_id > 0)
                    {
                        db.Entry(this).State = EntityState.Modified;
                    }
                    else
                    {
                        db.Entry(this).State = EntityState.Added;
                    }

                    db.SaveChanges();

                    if (File.Exists(HttpContext.Current.Server.MapPath("~/Uploads/Documents/" + documento_id + extensionAntigua)))
                    {
                        File.Delete(HttpContext.Current.Server.MapPath("~/Uploads/Documents/" + documento_id + extensionAntigua));
                    }

                    file.SaveAs(HttpContext.Current.Server.MapPath("~/Uploads/Documents/" + documento_id + extension));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 2
0
        public ResponseModel ValidarLogin(string usuario, string password)
        {
            var rm = new ResponseModel();

            try
            {
                using (var db = new Model_Sistema())
                {
                    password = HashHelper.MD5(password);
                    var usu = db.Usuario.Where(x => x.usuario1 == usuario)
                              .Where(x => x.clave == password)
                              .SingleOrDefault();

                    if (usu != null)
                    {
                        SessionHelper.AddUserToSession(usu.usuario_id.ToString());
                        rm.SetResponse(true);
                    }
                    else
                    {
                        rm.SetResponse(false, "Usuario o password incorrecto");
                    }
                }
            }
            catch
            {
                throw;
            }

            return(rm);
        }
Esempio n. 3
0
        public List <Usuario> Buscar(string criterio)
        {
            var    usuario   = new List <Usuario>();
            string estadousu = "";

            switch (criterio)
            {
            case "Activo":
                estadousu = "A";
                break;

            case "Inactivo":
                estadousu = "I";
                break;
            }

            try
            {
                using (var db = new Model_Sistema())
                {
                    usuario = db.Usuario.Include("Persona").Where(x => x.usuario1.Contains(criterio) ||
                                                                  x.Persona.apellido.Contains(criterio) ||
                                                                  x.estado == estadousu)
                              .ToList();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(usuario);
        }
Esempio n. 4
0
 public void Eliminar()
 {
     using (var db = new Model_Sistema())
     {
         if (this.persona_id > 0)
         {
             db.Entry(this).State = EntityState.Deleted;
             db.SaveChanges();
         }
     }
 }
Esempio n. 5
0
        public Categoria Obtener(int id)
        {
            var categorias = new Categoria();

            try
            {
                using (var db = new Model_Sistema())
                {
                    categorias = db.Categoria.Where(x => x.categoria_id == id).SingleOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(categorias);
        }
Esempio n. 6
0
        public Usuario Obtener(int id)
        {
            var usuarios = new Usuario();

            try
            {
                using (var db = new Model_Sistema())
                {
                    usuarios = db.Usuario.Include("Persona").Where(x => x.usuario_id == id).SingleOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(usuarios);
        }
Esempio n. 7
0
        public List <Categoria> Buscar(string criterio)
        {
            var categorias = new List <Categoria>();

            try
            {
                using (var db = new Model_Sistema())
                {
                    categorias = db.Categoria.Where(x => x.nombre.Contains(criterio) || x.descripcion.Contains(criterio)).ToList();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(categorias);
        }
Esempio n. 8
0
        public List <Persona> Buscar(string criterio)
        {
            var personas = new List <Persona>();

            try
            {
                using (var db = new Model_Sistema())
                {
                    personas = db.Persona.Where(x => x.nombre.Contains(criterio) || x.apellido.Contains(criterio)).ToList();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(personas);
        }
Esempio n. 9
0
        public Documento Obtener(int id)
        {
            var documentos = new Documento();

            try
            {
                using (var db = new Model_Sistema())
                {
                    documentos = db.Documento.Include("Categoria").Where(x => x.documento_id == id).SingleOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(documentos);
        }
Esempio n. 10
0
        public Persona Obtener(int id)
        {
            var personas = new Persona();

            try
            {
                using (var db = new Model_Sistema())
                {
                    personas = db.Persona.Where(x => x.persona_id == id).SingleOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(personas);
        }
Esempio n. 11
0
        public List <Documento> Buscar(string criterio)
        {
            var documentos = new List <Documento>();

            try
            {
                using (var db = new Model_Sistema())
                {
                    documentos = db.Documento.Include("Categoria").Where(x => x.nombre.Contains(criterio) || x.descripcion.Contains(criterio)).ToList();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(documentos);
        }
Esempio n. 12
0
        public Galeria Obtener(int id)
        {
            var galerias = new Galeria();

            try
            {
                using (var db = new Model_Sistema())
                {
                    galerias = db.Galeria.Include("Categoria").Where(x => x.galeria_id == id).SingleOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(galerias);
        }
Esempio n. 13
0
 public void Eliminar()
 {
     try
     {
         using (var db = new Model_Sistema())
         {
             if (this.categoria_id > 0)
             {
                 db.Entry(this).State = EntityState.Deleted;
                 db.SaveChanges();
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 14
0
        public List <Galeria> BuscarPorCategoria(string criterio)
        {
            var galerias = new List <Galeria>();
            int id       = Convert.ToInt32(criterio);

            try
            {
                using (var db = new Model_Sistema())
                {
                    galerias = db.Galeria.Include("Categoria").Where(x => x.categoria_id == id).ToList();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(galerias);
        }
Esempio n. 15
0
        // METHODS
        public List <Persona> Listar()
        {
            var personas = new List <Persona>();

            try
            {
                //DB connection
                using (var db = new Model_Sistema())
                {
                    personas = db.Persona.ToList();
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(personas);
        }
Esempio n. 16
0
        // METHODS
        public List <Documento> Listar()
        {
            var documentos = new List <Documento>();

            try
            {
                //DB connection
                using (var db = new Model_Sistema())
                {
                    documentos = db.Documento.Include("Categoria").ToList();
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(documentos);
        }
Esempio n. 17
0
        public ResponseModel GuardarPerfil(Persona persona)
        {
            var rm = new ResponseModel();

            using (var db = new Model_Sistema())
            {
                db.Configuration.ValidateOnSaveEnabled = false;

                var per = db.Entry(this);

                per.State = EntityState.Modified;

                if (persona != null)
                {
                    if (this.persona_id == 0)
                    {
                        per.Property(x => x.persona_id).IsModified = false;
                    }
                    if (this.estado == null)
                    {
                        per.Property(x => x.estado).IsModified = false;
                    }
                    if (this.dni == null)
                    {
                        per.Property(x => x.dni).IsModified = false;
                    }
                    if (this.apellido == null)
                    {
                        per.Property(x => x.apellido).IsModified = false;
                    }
                    if (this.nombre == null)
                    {
                        per.Property(x => x.nombre).IsModified = false;
                    }


                    db.SaveChanges();
                    rm.SetResponse(true);
                }
            }

            return(rm);
        }
Esempio n. 18
0
        // METHODS
        public List <Usuario> Listar()
        {
            var usuarios = new List <Usuario>();

            try
            {
                //DB connection
                using (var db = new Model_Sistema())
                {
                    usuarios = db.Usuario.Include("Persona").ToList();
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(usuarios);
        }
Esempio n. 19
0
        // METHODS
        public List <Galeria> Listar()
        {
            var galerias = new List <Galeria>();

            try
            {
                //DB connection
                using (var db = new Model_Sistema())
                {
                    galerias = db.Galeria.Include("Categoria").ToList();
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(galerias);
        }
Esempio n. 20
0
        // METHODS
        public List <Categoria> Listar()
        {
            var categorias = new List <Categoria>();

            try
            {
                //DB connection
                using (var db = new Model_Sistema())
                {
                    categorias = db.Categoria.ToList();
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(categorias);
        }
Esempio n. 21
0
        public void Eliminar()
        {
            try
            {
                var _context = new Model_Sistema();
                var doc      = _context.Documento.Find(documento_id);

                if (File.Exists(HttpContext.Current.Server.MapPath("~/Uploads/Documents/" + documento_id + doc.extension)))
                {
                    File.Delete(HttpContext.Current.Server.MapPath("~/Uploads/Documents/" + documento_id + doc.extension));
                }

                _context.Documento.Remove(doc);

                _context.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 22
0
 public Array TotalGalerias()
 {
     try
     {
         using (var db = new Model_Sistema())
         {
             var resultado =
                 from cat in db.Categoria
                 join gal in db.Galeria on cat.categoria_id
                 equals gal.categoria_id
                 into galeriaGroup
                 select new Consultas {
                 ID = cat.categoria_id, Nombre = cat.nombre, Count = galeriaGroup.Count()
             };
             return(resultado.ToArray());
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 23
0
 public void Guardar()
 {
     try
     {
         using (var db = new Model_Sistema())
         {
             if (this.persona_id > 0)
             {
                 db.Entry(this).State = EntityState.Modified;
             }
             else
             {
                 db.Entry(this).State = EntityState.Added;
             }
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 24
0
        public ResponseModel GuardarPerfil(HttpPostedFileBase Foto)
        {
            var rm = new ResponseModel();

            try
            {
                using (var db = new Model_Sistema())
                {
                    db.Configuration.ValidateOnSaveEnabled = false;

                    var usu = db.Entry(this);
                    usu.State = EntityState.Modified;

                    if (Foto != null)
                    {
                        const int size            = 1024 * 1024 * 5;
                        var       filtroextension = new[] { ".jpg", ".jpeg", ".png", ".gif" };
                        var       extensiones     = Path.GetExtension(Foto.FileName);

                        if (filtroextension.Contains(extensiones) && (Foto.ContentLength <= size))
                        {
                            avatar = usuario_id + "_avatar" + extensiones;
                            Foto.SaveAs(HttpContext.Current.Server.MapPath("~/Uploads/" + avatar));
                        }
                        else
                        {
                            usu.Property(x => x.avatar).IsModified = false;
                        }

                        if (this.usuario_id == 0)
                        {
                            usu.Property(x => x.usuario_id).IsModified = false;
                        }
                        if (this.persona_id == 0)
                        {
                            usu.Property(x => x.persona_id).IsModified = false;
                        }
                        if (this.usuario1 == null)
                        {
                            usu.Property(x => x.usuario1).IsModified = false;
                        }
                        if (this.nivel == null)
                        {
                            usu.Property(x => x.nivel).IsModified = false;
                        }
                        if (this.estado == null)
                        {
                            usu.Property(x => x.estado).IsModified = false;
                        }
                        if (this.clave == null)
                        {
                            usu.Property(x => x.clave).IsModified = false;
                        }

                        db.SaveChanges();
                        rm.SetResponse(true);
                    }
                }
            }
            catch (DbEntityValidationException)
            {
                throw;
            }

            return(rm);
        }