Exemplo n.º 1
0
        protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
        {
            string createdUsername = CreateUserWizard1.UserName;
            string createdPassword = CreateUserWizard1.Password;
            //dynamic profile = ProfileBase.Create(createdUsername);
            CreateUserWizardStep step1 = (CreateUserWizardStep)CreateUserWizard1.FindControl("Step1");
            //DropDownList k1 = (DropDownList)step1.ContentTemplateContainer.FindControl("ddlDept");
            DropDownList k2       = (DropDownList)step1.ContentTemplateContainer.FindControl("ddlRole");
            TextBox      k3       = (TextBox)step1.ContentTemplateContainer.FindControl("tbxName");
            TextBox      k4       = (TextBox)step1.ContentTemplateContainer.FindControl("UserName");
            TextBox      tbxEmail = (TextBox)step1.ContentTemplateContainer.FindControl("tbxEmail");

            Roles.AddUserToRole(createdUsername, k2.Text);

            // string encryptedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(createdPassword, "MD5");

            //try
            //{
            QHSEQuiz.Model.Hub hub = new QHSEQuiz.Model.Hub();

            hub.Name     = k3.Text;
            hub.UserName = createdUsername;
            //.Password = encryptedPassword;
            if (tbxEmail.Text != "")
            {
                hub.Email = tbxEmail.Text;
            }
            else
            {
                hub.Email = "N/A";
            }
            hub.Role = k2.SelectedItem.Text;

            context.Hubs.Add(hub);
            context.SaveChanges();
            //}

            //catch (DbEntityValidationException dbEx)
            //{
            //    foreach (var validationErrors in dbEx.EntityValidationErrors)
            //    {
            //        foreach (var validationError in validationErrors.ValidationErrors)
            //        {
            //            System.Diagnostics.Trace.TraceInformation("Property: {0} Error: {1}",
            //                                    validationError.PropertyName,
            //                                    validationError.ErrorMessage);
            //        }
            //    }
            //}
        }
Exemplo n.º 2
0
        protected void gvUser_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string username = gvUser.Rows[e.RowIndex].Cells[1].Text;

            string query = "SELECT DISTINCT UserId FROM aspnet_Users WHERE UserName = '******'";

            con = new SqlConnection(conStr);
            SqlDataAdapter adapter = new SqlDataAdapter(query, con);
            DataTable      dt      = new DataTable();

            adapter.Fill(dt);
            //DataSet dataset = new DataSet();
            //adapter.Fill(dataset);

            Guid userId = Guid.Parse(dt.Rows[0][0].ToString());



            using (QuizEntities context = new QuizEntities())
            {
                QHSEQuiz.Model.Hub hub = context.Hubs.Where(x => x.UserName == username).First();
                context.Hubs.Remove(hub);

                //aspnet_Profile profile = context.aspnet_Profile.Where(x => x.PropertyValuesString == username).First();
                //context.aspnet_Profile.Remove(profile);

                aspnet_Users user = context.aspnet_Users.Where(x => x.UserName == username).First();
                context.aspnet_Users.Remove(user);

                aspnet_Membership mem = context.aspnet_Membership.Where(x => x.UserId == userId).First();
                context.aspnet_Membership.Remove(mem);

                aspnet_UsersInRoles userInRole = context.aspnet_UsersInRoles.Where(x => x.UserId == userId).First();
                context.aspnet_UsersInRoles.Remove(userInRole);


                context.SaveChanges();
                Response.Redirect("~/Admin/ManageUsers.aspx");
            }
        }