Пример #1
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();
                }
            }
        }
Пример #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();
                }
            }
        }