protected void Page_Load(object sender, EventArgs e)
        {
            var AllUser = from p in db.Users
                          select p;

            var q = (from p in usm.aspnet_Roles
                     where p.RoleName == "Professor"
                     select p.RoleId).First();

            var h = (from p in usm.aspnet_Roles
                     where p.RoleName == "Header"
                     select p.RoleId).First();

            var d = (from p in usm.aspnet_Roles
                     where p.RoleName == "Dean"
                     select p.RoleId).First();

            foreach (var item in AllUser)
            {

                    var uName = (from p in usm.aspnet_Users
                                 where p.UserName == item.UserName
                                 select p.UserId).First();

                try
                {
                    var inRole = (from p in usm.aspnet_UsersInRoles
                                 where p.UserId == uName
                                 select p).First();
                }
                catch (Exception)
                {
                    aspnet_UsersInRole ro = new aspnet_UsersInRole();

                    if (item.UserLevelId == 2)
                    {
                        ro.RoleId = q;
                    }
                    else if (item.UserLevelId == 1)
                    {
                        ro.RoleId = h;
                    }
                    else
                    {
                        ro.RoleId = d;
                    }

                    ro.UserId = uName;

                    usm.aspnet_UsersInRoles.InsertOnSubmit(ro);
                    usm.SubmitChanges();
                }

            }
        }
Exemplo n.º 2
0
        protected void RegisterUser_CreatedUser(object sender, EventArgs e)
        {
            FormsAuthentication.SetAuthCookie(RegisterUser.UserName, createPersistentCookie: false);

            string email = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Email")).Text;
            int dept = Convert.ToInt32(((DropDownList)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Dept")).SelectedValue);
            int prefix = Convert.ToInt32(((DropDownList)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Prefix")).SelectedValue);
            string firstName = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("FirstName")).Text;
            string lastName = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("LastName")).Text;

            User x = new User();
            x.UserName = RegisterUser.UserName;
            x.Email = email;
            x.DeptId = dept;
            x.PrefixId = prefix;
            x.FirstName = firstName;
            x.LastName = lastName;
            x.StatusId = 0;
            x.UserLevelId = 2;

            db.Users.InsertOnSubmit(x);
            db.SubmitChanges();

            var q = (from p in usm.aspnet_Roles
                     where p.RoleName == "Professor"
                     select p.RoleId).First();

            var uName = (from p in usm.aspnet_Users
                         where p.UserName == RegisterUser.UserName
                         select p.UserId).First();

            aspnet_UsersInRole ro = new aspnet_UsersInRole();
            ro.RoleId = q;
            ro.UserId = uName;

            usm.aspnet_UsersInRoles.InsertOnSubmit(ro);
            usm.SubmitChanges();

            string continueUrl = RegisterUser.ContinueDestinationPageUrl;
            if (!OpenAuth.IsLocalUrl(continueUrl))
            {
                continueUrl = "~/";
            }
            Response.Redirect(continueUrl);
        }
		private void detach_aspnet_UsersInRoles(aspnet_UsersInRole entity)
		{
			this.SendPropertyChanging();
			entity.aspnet_Role = null;
		}
 partial void Deleteaspnet_UsersInRole(aspnet_UsersInRole instance);
 partial void Updateaspnet_UsersInRole(aspnet_UsersInRole instance);
 partial void Insertaspnet_UsersInRole(aspnet_UsersInRole instance);
		private void attach_aspnet_UsersInRoles(aspnet_UsersInRole entity)
		{
			this.SendPropertyChanging();
			entity.aspnet_User = this;
		}