Esempio n. 1
0
        private bool Test()
        {
            var item = (TRole)cmbRole.SelectedItem as TRole;

            TUsers user = new TUsers()
            {
                Name                = txtName.Text,
                Surname             = txtSurname.Text,
                Middlename          = txtMiddleName.Text,
                PassportNumber      = int.Parse(txtNumber.Text),
                PassportSeria       = int.Parse(txtSeria.Text),
                Photo               = bs,
                IdRole              = item.IdRole,
                IdRoleNavigationLog = item,
            };

            var results = new List <System.ComponentModel.DataAnnotations.ValidationResult>();
            var context = new ValidationContext(user);

            if (!Validator.TryValidateObject(user, context, results, true))
            {
                foreach (var error in results)
                {
                    MessageBox.Show(error.ErrorMessage);
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 2
0
        void Add()
        {
            var item = (TRole)cmbRole.SelectedItem as TRole;

            if (Test() == false)
            {
                return;
            }

            TUsers users = new TUsers()
            {
                Name = txtName.Text, Surname = txtSurname.Text, Middlename = txtMiddleName.Text, PassportNumber = int.Parse(txtNumber.Text), PassportSeria = int.Parse(txtSeria.Text), Photo = bs, IdRoleNavigationLog = item, IdRole = item.IdRole, TSpec = new TSpec {
                    Title = "sdsdsd"
                }
            };

            context.TUsers.Add(users);
            ocUsers.Add(users);
        }