Example #1
0
        public List<UsuarioModel> Lista(int? id)
        {
            List<UsuarioModel> lista = new List<UsuarioModel>();

            SqlParameter[] parms = new SqlParameter[] { new SqlParameter("@U_Id", DBNull.Value) };
            if (id != null)
            {
                parms[0].Value = id.Value;
            }

            DataTable dt = db.ExecuteReader<SqlDataReader>("proc_buscaUsuario", parms);

            UsuarioModel _u;
            foreach (DataRow dr in dt.Rows)
            {
                _u = new UsuarioModel();
                _u.Id = Convert.ToInt32(dr["U_ID"]);
                _u.Login = dr["U_LOGIN"].ToString();
                _u.Senha = dr["U_SENHA"].ToString();
                _u.ControleAcesso = Convert.ToBoolean(dr["U_CONTROLEACESSO"]);
                _u.Cadastro = Convert.ToBoolean(dr["U_CADASTRO"]);
                _u.Consulta = Convert.ToBoolean(dr["U_CONSULTA"]);
                _u.Importar = Convert.ToBoolean(dr["U_IMPORTAR"]);
                _u.IsAtivo = Convert.ToBoolean(dr["U_ISATIVO"]);

                lista.Add(_u);
            }

            return lista;

        }
Example #2
0
 public ActionResult Index()
 {
     UsuarioModel user = new UsuarioModel();
     if (Session["login"] != null)
         user = (UsuarioModel)Session["login"];
     @ViewBag.NomeUsuario = user.Login;
     return View();
 }
Example #3
0
        public List<UsuarioModel> Filtro(string nome, bool? inauguracao, bool? especial, int? idOrigem, int? idProfissao)
        {
            SqlParameter[] parms = new SqlParameter[] {
                new SqlParameter("@U_LOGIN", DBNull.Value),
                new SqlParameter("@U_CONTROLEACESSO", DBNull.Value),
                new SqlParameter("@U_CADASTRO", DBNull.Value),
                new SqlParameter("@U_CONSULTA", DBNull.Value),
                new SqlParameter("@U_IMPORTAR", DBNull.Value),
                new SqlParameter("@U_ISATIVO", DBNull.Value),
            };

            if (nome != null)
                parms[0].Value = nome;
            if (inauguracao != null)
                parms[1].Value = inauguracao.Value;
            if (especial != null)
                parms[2].Value = especial.Value;
            if (idOrigem != null)
                parms[3].Value = idOrigem.Value;
            if (idProfissao != null)
                parms[4].Value = idProfissao.Value;

            DataTable dt = db.ExecuteReader<SqlDataReader>("proc_filtroUsuario", parms);

            List<UsuarioModel> lista = new List<UsuarioModel>();
            UsuarioModel _u;
            foreach (DataRow dr in dt.Rows)
            {
                _u = new UsuarioModel();
                _u.Id = Convert.ToInt32(dr["P_ID"]);
                _u.Login = dr["U_LOGIN"].ToString();
                _u.Senha = dr["U_SENHA"].ToString();
                _u.ControleAcesso = Convert.ToBoolean(dr["U_CONTROLEACESSO"]);
                _u.Cadastro = Convert.ToBoolean(dr["U_CADASTRO"]);
                _u.Consulta = Convert.ToBoolean(dr["U_CONSULTA"]);
                _u.Importar = Convert.ToBoolean(dr["U_IMPORTAR"]);
                _u.IsAtivo = Convert.ToBoolean(dr["U_ISATIVO"]);

                lista.Add(_u);
            }

            return lista;

        }
Example #4
0
        public ActionResult Edit(UsuarioModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Usuario uData = new Usuario();
                    uData.Atualizar(model);

                    return RedirectToAction("Index");
                }
                else
                {
                    return View(model);
                }
            }
            catch
            {
                return View(model);
            }
        }
Example #5
0
        public void Inserir(UsuarioModel model)
        {
            SqlParameter[] parms = new SqlParameter[] {
                new SqlParameter("@U_LOGIN", model.Login),
                new SqlParameter("@U_SENHA", model.Senha),
                new SqlParameter("@U_CONTROLEACESSO", model.ControleAcesso),
                new SqlParameter("@U_CADASTRO", model.Cadastro),
                new SqlParameter("@U_CONSULTA", model.Consulta),
                new SqlParameter("@U_IMPORTAR", model.Importar),
                new SqlParameter("@U_ISATIVO", model.IsAtivo)
            };

            DataTable dt = db.ExecuteReader<SqlDataReader>("proc_insereUsuario", parms);
        }
Example #6
0
        public bool AutenticaUsuario(string usuario, string senha, ref UsuarioModel user)
        {
            SqlParameter[] parms = new SqlParameter[] {
                new SqlParameter("@U_LOGIN",usuario)
            };

            DataTable dt = db.ExecuteReader<SqlDataReader>("proc_buscaUsuarioByLogin", parms);

            UsuarioModel _u = null;
            foreach (DataRow dr in dt.Rows)
            {
                _u = new UsuarioModel();
                _u.Id = Convert.ToInt32(dr["U_ID"]);
                _u.Login = dr["U_LOGIN"].ToString();
                _u.Senha = dr["U_SENHA"].ToString();
                _u.ControleAcesso = Convert.ToBoolean(dr["U_CONTROLEACESSO"]);
                _u.Cadastro = Convert.ToBoolean(dr["U_CADASTRO"]);
                _u.Consulta = Convert.ToBoolean(dr["U_CONSULTA"]);
                _u.Importar = Convert.ToBoolean(dr["U_IMPORTAR"]);
                _u.IsAtivo = Convert.ToBoolean(dr["U_ISATIVO"]);

                break;
            }

            if (_u == null)
                return false;

            if (senha == _u.Senha && _u.IsAtivo)
            {
                _u.Senha = ""; //limpar senha para nao ficar no cookie da Session
                user = _u;
                return true;
            }
            else
                return false;
        }
Example #7
0
        public void Atualizar(UsuarioModel model)
        {
            SqlParameter[] parms = new SqlParameter[] {
                new SqlParameter("@U_ID", model.Id),
                new SqlParameter("@U_LOGIN", model.Login),
                new SqlParameter("@U_SENHA", model.Senha),
                new SqlParameter("@U_CONTROLEACESSO", model.ControleAcesso),
                new SqlParameter("@U_CADASTRO", model.Cadastro),
                new SqlParameter("@U_CONSULTA", model.Consulta),
                new SqlParameter("@U_IMPORTAR", model.Importar),
                new SqlParameter("@U_ISATIVO", model.IsAtivo)
            };

            db.ExecuteNonQuery("proc_atualizaUsuario", parms);
        }