Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (tbSenha.Text.Equals(tbSenha2.Text))
            {
                Mongo mongo      = new Mongo();
                var   database   = mongo.getserver();
                var   collection = database.GetCollection <User>("user");

                var filter  = new BsonDocument("Cpf", user_.Cpf);
                var results = collection.Find(filter).ToList();
                if (results.Count == 0)
                {
                    throw new Exception();
                }

                User user = results.First();

                Cript cript = new Cript();
                user.Password = cript.ComputeSha256Hash(tbSenha.Text);

                var filter1 = Builders <User> .Filter.Eq(s => s.Id, user.Id);

                var result = collection.ReplaceOne(filter1, user);

                MessageBox.Show("Senha alterada com sucesso");
                this.Dispose();
            }
            else
            {
                MessageBox.Show("senhas não dão match ou não são validas");
            }
        }
Esempio n. 2
0
        public void unblock(string cpf, string email)
        {
            Mongo mongo      = new Mongo();
            var   database   = mongo.getserver();
            var   collection = database.GetCollection <User>("user");
            var   filter     = new BsonDocument("Cpf", cpf);
            var   results    = collection.Find(filter).ToList();

            if (results.Count == 0)
            {
                throw new Exception();
            }

            User user = results.First();

            user.UserStatus = UserStatus.NORMAL;

            var userFilter = Builders <User> .Filter.Eq(s => s.Id, user.Id);

            collection.ReplaceOne(userFilter, user);

            var emailSender = new Email();
            var body        = "Olá " + user.Name + " seu usuário foi desbloqueado com sucesso!";

            emailSender.email_send(email, "Desbloqueio", "", body);
        }
        public calculadoraCaloriasDiarias()
        {
            Mongo mongo      = new Mongo();
            var   database   = mongo.getserver();
            var   collection = database.GetCollection <Product>("product");

            products = collection.Find(_ => true).ToList();
            if (products.Count == 0)
            {
                throw new NoProductException("Nenhum produto cadastrado na base, impossivel realizar calculos");
            }
            InitializeComponent();
        }
Esempio n. 4
0
        public ControleDeUsuario()
        {
            InitializeComponent();
            Mongo mongo      = new Mongo();
            var   database   = mongo.getserver();
            var   collection = database.GetCollection <User>("user");

            list = collection.Find(_ => true).ToList();
            foreach (User user in list)
            {
                string[] userString = new string[] { user.Name, user.UserStatus.ToString(), user.Profile.ToString() };
                dataGridView1.Rows.Add(userString);
            }
        }
Esempio n. 5
0
        public ConsultarProdutos()
        {
            InitializeComponent();
            Mongo mongo      = new Mongo();
            var   database   = mongo.getserver();
            var   collection = database.GetCollection <Product>("product");

            list = collection.Find(_ => true).ToList();
            foreach (Product user in list)
            {
                string[] userString = { user.Name, user.Tipo, user.Classe, user.Calorias.ToString(CultureInfo.InvariantCulture) };
                dataGridView1.Rows.Add(userString);
            }
        }
Esempio n. 6
0
        private void updateCombo()
        {
            Mongo mongo      = new Mongo();
            var   database   = mongo.getserver();
            var   collection = database.GetCollection <Product>("product");

            resultes = collection.Find(_ => true).ToList();
            comboBox1.Items.Clear();
            if (resultes.Count == 0)
            {
                MessageBox.Show("No Products");
            }

            List <String> list = resultes.Select(result => result.Name).ToList();

            comboBox1.Items.AddRange(list.ToArray <object>());
        }
Esempio n. 7
0
        private void filter(String filters)
        {
            dataGridView1.Rows.Clear();
            Mongo mongo      = new Mongo();
            var   database   = mongo.getserver();
            var   collection = database.GetCollection <Product>("product");

            var filter = new BsonDocument {
                { "Name", new BsonDocument {
                      { "$regex", filters }, { "$options", "i" }
                  } }
            };

            var results = collection.Find(filter).ToList();

            foreach (Product user in results)
            {
                string[] userString = { user.Name, user.Tipo, user.Classe, user.Calorias.ToString(CultureInfo.InvariantCulture) };
                dataGridView1.Rows.Add(userString);
            }
        }
Esempio n. 8
0
        public void block(string cpf)
        {
            Mongo mongo      = new Mongo();
            var   database   = mongo.getserver();
            var   collection = database.GetCollection <User>("user");
            var   filter     = new BsonDocument("Cpf", cpf);
            var   results    = collection.Find(filter).ToList();

            if (results.Count == 0)
            {
                throw new Exception();
            }

            User user = results.First();

            user.UserStatus = UserStatus.BLOQUED;

            var userFilter = Builders <User> .Filter.Eq(s => s.Id, user.Id);

            collection.ReplaceOne(userFilter, user);
        }
Esempio n. 9
0
        private void button1_Click(object sender, EventArgs e)
        {
            Mongo mongo      = new Mongo();
            var   database   = mongo.getserver();
            var   collection = database.GetCollection <User>("user");

            int i = 0;

            foreach (User user in list)
            {
                if (dataGridView1.Rows[i].Cells[1].Value.ToString().Equals("NORMAL"))
                {
                    user.UserStatus = UserStatus.NORMAL;
                }
                if (dataGridView1.Rows[i].Cells[1].Value.ToString().Equals("DELETED"))
                {
                    user.UserStatus = UserStatus.DELETED;
                }
                if (dataGridView1.Rows[i].Cells[1].Value.ToString().Equals("BLOQUED"))
                {
                    user.UserStatus = UserStatus.BLOQUED;
                }

                if (dataGridView1.Rows[i].Cells[2].Value.ToString().Equals("1"))
                {
                    user.Profile = 1;
                }
                if (dataGridView1.Rows[i].Cells[2].Value.ToString().Equals("2"))
                {
                    user.Profile = 2;
                }

                var filter = Builders <User> .Filter.Eq(s => s.Id, user.Id);

                var result = collection.ReplaceOne(filter, user);

                i++;
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            name = this.comboBoxAlimentos.GetItemText(this.comboBoxAlimentos.SelectedItem);
            Mongo mongo      = new Mongo();
            var   database   = mongo.getserver();
            var   filter     = new BsonDocument("Name", name);
            var   collection = database.GetCollection <Product>("product");
            var   results    = collection.Find(filter).ToList();

            if (results.Count == 0)
            {
                throw new Exception("Usuario inexistente ");
            }

            Product product       = results.First();
            var     multiplicador = 1.0;

            if (float.Parse(textBox2.Text) > 0)
            {
                multiplicador = float.Parse(textBox2.Text);
            }

            product.CaloriasTotais = (float)(product.Calorias * multiplicador);
            product.Qtd            = (float)multiplicador;
            caloriasIngeridas     += product.CaloriasTotais;
            labelTotal.Text        = "Calorias Ingeridas: " + caloriasIngeridas;

            var config = new MapperConfiguration(cfg => {
                cfg.CreateMap <Product, ProductView>();
            });
            IMapper iMapper     = config.CreateMapper();
            var     productView = iMapper.Map <Product, ProductView>(product);

            listBox1.Items.Add(productView);
            listBox1.Refresh();
        }
Esempio n. 11
0
        public User Login(string cpf, string senha)
        {
            Mongo mongo      = new Mongo();
            var   database   = mongo.getserver();
            var   collection = database.GetCollection <User>("user");

            var filter  = new BsonDocument("Cpf", cpf);
            var results = collection.Find(filter).ToList();

            if (results.Count == 0)
            {
                throw new Exception("Usuario inexistente ");
            }

            User user = results.First();

            Cript cript = new Cript();

            if (user.UserStatus == UserStatus.DELETED)
            {
                throw new Exception("Usuario inexistente ");
            }

            if (user.UserStatus == UserStatus.BLOQUED)
            {
                throw new Exception("Usuario Bloqueado");
            }

            if (!user.Password.Equals(cript.ComputeSha256Hash(senha)))
            {
                throw new WrongcredentialsException("Senha Invalida");
            }


            return(user);
        }
Esempio n. 12
0
        private void Button1_Click_1(object sender, EventArgs e)
        {
            Mongo            mongo            = new Mongo();
            CadastrarUsuario cadastrarUsuario = new CadastrarUsuario(mongo.getserver());
            User             user             = new User(tbNome.Text, tbSenha.Text, tbmCpf.Text, tbRg.Text);
            var status = cadastrarUsuario.cadastro(user);

            if (status.Equals("user_existent"))
            {
                string text = "Usuario ja cadastrado";
                MessageBox.Show(text);
                clearFields();
            }
            else if (status.Equals("success"))
            {
                MessageBox.Show("Usuario cadastrado com exito");
                frm.Show();
                this.Dispose();
            }
            else
            {
                MessageBox.Show("Algum campo esta em branco");
            }
        }