コード例 #1
0
        // metodo validar login

        public ResponseModel validarlogin(string usuarios, string Password)
        {
            var rm = new ResponseModel();

            try
            {
                using (var db = new proyecto_ARTC())
                {
                    Password = HashHelper.MD5(Password);
                    var usuario = db.Usuario.Where(x => x.nomb_usu == usuarios)
                                  .Where(x => x.pas_usu == Password)
                                  .SingleOrDefault();

                    if (usuario != null)
                    {
                        SessionHelper.AddUserToSession(usuario.usuario_id.ToString());
                        rm.SetResponse(true);
                    }
                    else
                    {
                        rm.SetResponse(false, "Usuaro y/o password son incorrectos ....");
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(rm);
        }
コード例 #2
0
        //metodo eliminar

        public void eliminar()
        {
            try
            {
                using (var db = new proyecto_ARTC())
                {
                    db.Entry(this).State = EntityState.Deleted;
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #3
0
        //metodo listar

        public List <Control> listar() //retorna una coleccion de resgistro
        {
            var objcontrol = new List <Control>();

            try
            {
                using (var db = new proyecto_ARTC())
                {
                    objcontrol = db.Control.ToList();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(objcontrol);
        }
コード例 #4
0
        //metodo listar

        public List <Sensor> listar() //retorna una coleccion de resgistro
        {
            var objsensor = new List <Sensor>();

            try
            {
                using (var db = new proyecto_ARTC())
                {
                    objsensor = db.Sensor.ToList();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(objsensor);
        }
コード例 #5
0
        //metodo listar

        public List <Persona> listar() //retorna una coleccion de resgistro
        {
            var objpersona = new List <Persona>();

            try
            {
                using (var db = new proyecto_ARTC())
                {
                    objpersona = db.Persona.Include("usuario").ToList();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(objpersona);
        }
コード例 #6
0
        //metodo listar

        public List <Usuario> listar() //retorna una coleccion de resgistro
        {
            var objusuario = new List <Usuario>();

            try
            {
                using (var db = new proyecto_ARTC())
                {
                    objusuario = db.Usuario.Include("persona").ToList();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(objusuario);
        }
コード例 #7
0
        //metodo listar

        public List <Reservorio> listar() //retorna una coleccion de resgistro
        {
            var objreservorio = new List <Reservorio>();

            try
            {
                using (var db = new proyecto_ARTC())
                {
                    objreservorio = db.Reservorio.ToList();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(objreservorio);
        }
コード例 #8
0
        //metodo obtener

        public Control obtener(int id) //retorna solo un objeto
        {
            var objcontrol = new Control();

            try
            {
                using (var db = new proyecto_ARTC())
                {
                    objcontrol = db.Control.Where(x => x.control_id == id).SingleOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(objcontrol);
        }
コード例 #9
0
        //metodo obtener

        public Sensor obtener(int id) //retorna solo un objeto
        {
            var objsensor = new Sensor();

            try
            {
                using (var db = new proyecto_ARTC())
                {
                    objsensor = db.Sensor.Where(x => x.sensor_id == id).SingleOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(objsensor);
        }
コード例 #10
0
        //metodo obtener

        public Persona obtener(int id) //retorna solo un objeto
        {
            var objpersona = new Persona();

            try
            {
                using (var db = new proyecto_ARTC())
                {
                    objpersona = db.Persona.Include("usuario").Where(x => x.persona_id == id).SingleOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(objpersona);
        }
コード例 #11
0
        //metodo obtener

        public Usuario obtener(int id) //retorna solo un objeto
        {
            var objusuario = new Usuario();

            try
            {
                using (var db = new proyecto_ARTC())
                {
                    objusuario = db.Usuario.Include("persona").Where(x => x.usuario_id == id).SingleOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(objusuario);
        }
コード例 #12
0
        //metodo obtener

        public Reservorio obtener(int id) //retorna solo un objeto
        {
            var objreservorio = new Reservorio();

            try
            {
                using (var db = new proyecto_ARTC())
                {
                    objreservorio = db.Reservorio.Where(x => x.reservorio_id == id).SingleOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(objreservorio);
        }
コード例 #13
0
        // metodo guardar

        public void guardar()
        {
            try
            {
                using (var db = new proyecto_ARTC())
                {
                    if (this.control_id > 0)
                    {
                        //si existe un valor mayor a cero es porque exiiste el registro
                        db.Entry(this).State = EntityState.Modified;
                    }
                    else
                    {
                        //si no existe el registro lo graba(nuevo)
                        db.Entry(this).State = EntityState.Added;
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #14
0
        ////metodo guardar perfil

        public ResponseModel guardarperfil(HttpPostedFileBase foto)
        {
            var rm = new ResponseModel();

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

                    var usu = db.Entry(this);
                    usu.State = EntityState.Modified; //permite modificar el usuario

                    if (foto != null)
                    {
                        string extension = Path.GetExtension(foto.FileName).ToLower(); //el path me permite obtener algunas propiedades del archivo

                        int size            = 1024 * 1014 * 5;                         //es el tamaño que recibe
                        var filtroextension = new[] { ".jpg", ".jpeg", ".png", ".gif" };
                        var extensiones     = Path.GetExtension(foto.FileName);        //la foto

                        if (filtroextension.Contains(extensiones) && (foto.ContentLength <= size))
                        {
                            string archivo = Path.GetFileName(foto.FileName);//es lo que vamos a obtener

                            //la ruta doonde guardaremos las imagenes
                            foto.SaveAs(HttpContext.Current.Server.MapPath("~/fotousu/" + archivo));
                            this.foto_usu = archivo;
                        }
                    }
                    else
                    {
                        usu.Property(x => x.foto_usu).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.nomb_usu == null)
                    {
                        usu.Property(x => x.nomb_usu).IsModified = false;
                    }
                    if (this.pas_usu == null)
                    {
                        usu.Property(x => x.pas_usu).IsModified = false;
                    }
                    if (this.nivel_usu == null)
                    {
                        usu.Property(x => x.nivel_usu).IsModified = false;
                    }
                    if (this.estado_usu == null)
                    {
                        usu.Property(x => x.estado_usu).IsModified = false;
                    }

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