Beispiel #1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            ElanDbContext db    = new ElanDbContext();
            var           x     = 20;
            var           y     = 20;
            var           count = 0;

            foreach (var item in db.Houses)
            {
                count++;
                // var itemprice =( Convert.ToInt32(item.Price) - ((Convert.ToInt32(item.Price) * Convert.ToInt32(item.Discount) / 100))).ToString();

                ElanControl1 elanControl = new ElanControl1();
                elanControl.label1.Text = item.Adress;
                //  elanControl.label2.Text = itemprice;
                elanControl.label3.Text = item.PhoneNumber;
                elanControl.label4.Text = item.Discount;

                elanControl.Top  = y;
                elanControl.Left = x;

                this.panel1.Controls.Add(elanControl);
                x += elanControl.Width + 20;
                if (count == 4)
                {
                    count = 0;
                    y    += elanControl.Height + 20;
                    x     = 20;
                }
            }
        }
Beispiel #2
0
        private void button_register_Click(object sender, EventArgs e)
        {
            ElanDbContext db   = new ElanDbContext();
            User          user = new User
            {
                Name            = textBox_name.Text,
                Email           = textBox_email.Text,
                Password        = textBox_password.Text,
                Surname         = textBox_surname.Text,
                ConfirmPassword = textBox_confirmpassword.Text
            };


            ValidationContext       context = new ValidationContext(user);
            List <ValidationResult> list    = new List <ValidationResult>();
            var result = Validator.TryValidateObject(user, context, list, true);

            if (result)
            {
                db.Users.Add(user);
                db.SaveChanges();
            }
            else
            {
                foreach (var item in list)
                {
                    label6.Text += "\n" + item.ErrorMessage.ToString();
                }
            }
        }
Beispiel #3
0
        private void button_addhouse_Click(object sender, EventArgs e)
        {
            ElanDbContext db    = new ElanDbContext();
            House         house = new House
            {
                Adress = textBox_adress.Text,
                //  Discount = textBox_discount.Text,
                PhoneNumber = textBox_phonenumber.Text,
                Price       = textBox_price.Text
            };



            ValidationContext       context = new ValidationContext(house);
            List <ValidationResult> list    = new List <ValidationResult>();
            var result = Validator.TryValidateObject(house, context, list, true);

            if (result)
            {
                db.Houses.Add(house);
                db.SaveChanges();

                MainForm main = new MainForm();
                main.ShowDialog();
            }
            else
            {
                foreach (var item in list)
                {
                    label4.Text += "\n" + item.ErrorMessage.ToString();
                }
            }
        }
Beispiel #4
0
        private void button_login_Click(object sender, EventArgs e)
        {
            LoginModel loginModel = new LoginModel
            {
                Email    = textBox_email.Text,
                Password = textBox_password.Text
            };

            ElanDbContext db = new ElanDbContext();

            var user = db.Users.FirstOrDefault(x => x.Email == loginModel.Email &&
                                               x.Password == loginModel.Password);

            if (user != null)
            {
                AdvertisementAdding advertisementAdding = new AdvertisementAdding();
                advertisementAdding.ShowDialog();
            }
            else
            {
                MessageBox.Show("Email or password is incorrect");
            }
        }