Exemple #1
0
        private void CreateClick(object sender, EventArgs e)
        {
            errorProvider.ClearErrors();
            if (!ValidateChildren() || errorProvider.HasErrors)
            {
                DialogResult = DialogResult.None;
                return;
            }
            var user = new User
            {
                LastName   = ParseToDefaultForm(txtLastName.Text),
                FirstName  = ParseToDefaultForm(txtFirstName.Text),
                MiddleName = ParseToDefaultForm(txtMiddleName.Text)
            };
            var newPass = new ChangePasswordForm().NewPassword();

            if (newPass == null)
            {
                DialogResult = DialogResult.None;
                return;
            }
            user.UserPassword = Security.CreateHash(newPass);
            using (var dbUser = new ApplicationEntitie(0))
            {
                var roles = ccbRoles.Properties.Items.Cast <CheckedListBoxItem>()
                            .
                            Where(item => item.CheckState == CheckState.Checked)
                            .
                            Select(r => (int)r.Value);
                foreach (var role in dbUser.Roles.Where(rr => roles.Contains(rr.Id)))
                {
                    dbUser.Roles.Attach(role);
                    user.Roles.Add(role);
                }
                dbUser.Users.Add(user);
                dbUser.SaveChanges();
                NewUser = user;
            }
        }
Exemple #2
0
 private void CreateClick(object sender, EventArgs e)
 {
     errorProvider.ClearErrors();
     if (!ValidateChildren() || errorProvider.HasErrors)
     {
         DialogResult = DialogResult.None;
         return;
     }
     var user = new User
     {
         LastName = ParseToDefaultForm(txtLastName.Text),
         FirstName = ParseToDefaultForm(txtFirstName.Text),
         MiddleName = ParseToDefaultForm(txtMiddleName.Text)
     };
     var newPass = new ChangePasswordForm().NewPassword();
     if (newPass == null)
     {
         DialogResult = DialogResult.None;
         return;
     }
     user.UserPassword = Security.CreateHash(newPass);
     using (var dbUser = new ApplicationEntitie(0))
     {
         var roles = ccbRoles.Properties.Items.Cast<CheckedListBoxItem>()
             .
             Where(item => item.CheckState == CheckState.Checked)
             .
             Select(r => (int) r.Value);
         foreach (var role in dbUser.Roles.Where(rr => roles.Contains(rr.Id)))
         {
             dbUser.Roles.Attach(role);
             user.Roles.Add(role);
         }
         dbUser.Users.Add(user);
         dbUser.SaveChanges();
         NewUser = user;
     }
 }