protected void RadButtonCreate_Click(object sender, EventArgs e) { if (Membership.FindUsersByName(TextBoxUserName.Text).Count == 0 && Membership.FindUsersByEmail(TextBoxUserName.Text).Count == 0) { MembershipUser membershipUser = Membership.CreateUser(TextBoxUserName.Text, TextBoxPassword.Text, TextBoxUserName.Text); Roles.AddUserToRole(TextBoxUserName.Text, "User"); // Roles.AddUserToRole(TextBoxUserName.Text, "Administrator"); PlaceHolderCreateAdmin.Visible = false; CreateAdminStatus.Text = "User account " + TextBoxUserName.Text + " is created"; DALPortalDataContext dc = new DataAccess.Database.DALPortalDataContext(); userSetting setting = new userSetting(); setting.userId = (Guid)membershipUser.ProviderUserKey; setting.name = TextBoxName.Text; setting.companyCode = companyDDL.SelectedValue; setting.defaultCultureCode = "nl"; dc.userSettings.InsertOnSubmit(setting); dc.SubmitChanges(); Session["username"] = TextBoxUserName.Text; Session["name"] = TextBoxName.Text; Response.Redirect("~/Pages/AddRole.aspx"); } else CreateAdminStatus.Text = "There is already a user with that username"; }
protected void RadButtonCreate_Click(object sender, EventArgs e) { DALPortalDataContext dc = new DALPortalDataContext(); string username = (string)Session["username"]; string name = (string)Session["name"]; string[] items = new string[RadListBoxDestination.Items.Count]; for (int i = 0; RadListBoxDestination.Items.Count > i; i++) //RadListBoxItem item in RadListBoxDestination.Items) { items[i] = RadListBoxDestination.Items[i].Value; } Guid userId2 = dc.Users.Where(c => c.UserName.Equals(username)).Select(c => c.UserId).SingleOrDefault(); List<userRole> roles = dc.userRoles.Where(c => c.userId.Equals(userId2)).ToList(); for (int i = 0; roles.Count() > i; i++) { if (!items.Contains(roles[i].roleCode)) { // roles.RemoveAt(i); dc.userRoles.DeleteOnSubmit(roles[i]); } } for (int i = 0; items.Count() > i; i++) { if (!roles.Any(c => c.roleCode.Equals(items[i]))) { userRole roleUser = new userRole { userId = userId2, roleCode = items[i] }; dc.userRoles.InsertOnSubmit(roleUser); } } userSetting userSetting = dc.userSettings.Where(c => c.userId.Equals(userId2)).SingleOrDefault(); if (userSetting == null) { userSetting = new userSetting { userId = userId2 }; userSetting.companyCode = "ZW"; userSetting.defaultCultureCode = "nl"; userSetting.name = TextBoxName.Text; userSetting.siteAdmin = adminCheckBox.Checked; dc.userSettings.InsertOnSubmit(userSetting); } else { userSetting.siteAdmin = adminCheckBox.Checked; userSetting.name = TextBoxName.Text; userSetting.companyCode = companyDDL.SelectedValue; } dc.SubmitChanges(); Response.Redirect("~/Pages/UserAccounts.aspx"); }
private void detach_userSettings(userSetting entity) { this.SendPropertyChanging(); entity.company = null; }
partial void DeleteuserSetting(userSetting instance);
partial void UpdateuserSetting(userSetting instance);
partial void InsertuserSetting(userSetting instance);