/// <summary>
 /// Adds a new user.
 /// </summary>
 /// <param name="sessionID">The sessionID of the current session</param>
 /// <param name="username">The username.</param>
 /// <param name="password">The password.</param>
 /// <param name="firstname">The firstname.</param>
 /// <param name="lastname">The lastname.</param>
 /// <param name="roles">The roles.</param>
 public void AddUser(string sessionID, string username, string password, string firstname, string lastname, List<string> roles)
 {
     UsersTableAdapter uta = new UsersTableAdapter();
     int id = (int)((decimal)(uta.InsertAndGetIdentity(username, password, "", firstname, lastname)));
     foreach (string role in roles)
     {
         RolesTableAdapter rta = new RolesTableAdapter();
         rta.Insert(id, role);
     }
 }
        private void PageDataRefresh()
        {
            string uID = Request.QueryString["id"];

            if (uID == null || uID == "0")
            {
                Response.Redirect("~/Admin/RegisterUser.aspx");
            }

            /* *********** Configure DAL *********** */
            UsersAndRolesTableAdapter userAdapter = new UsersAndRolesTableAdapter();

            FvUserView.DataSource = userAdapter.GetUserByID(uID);
            FvUserView.DataBind();

            CheckBoxList Roles_cbl = (CheckBoxList)FvUserView.FindControl("CblRoles");

            RolesTableAdapter roleAdapter = new RolesTableAdapter();

            Roles_cbl.DataSource     = roleAdapter.GetData();
            Roles_cbl.DataValueField = "RoleID";
            Roles_cbl.DataTextField  = "Name";
            Roles_cbl.DataBind();

            UserRolesTableAdapter userRolesAdapter = new UserRolesTableAdapter();
            int RoleCount = (int)userRolesAdapter.CountRolesByUserID(uID);

            if (RoleCount > 0)
            {
                DataTable Roles = userRolesAdapter.GetUserRolesByID(uID).CopyToDataTable();

                foreach (DataRow row in Roles.Rows)
                {
                    for (int i = 0; i < Roles_cbl.Items.Count; i++)
                    {
                        if (Roles.Rows[Roles.Rows.IndexOf(row)]["Name"].ToString() == Roles_cbl.Items[i].Text.ToString())
                        {
                            Roles_cbl.Items[i].Selected = true;
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Adds the user to role.
 /// </summary>
 /// <param name="sessionID">The sessionID of the current session</param>
 /// <param name="EmployeeID">The employee ID of the employee.</param>
 /// <param name="role">The role that employee is to be added to.</param>
 public void AddUserToRole(string sessionID, int EmployeeID, string role)
 {
     RolesTableAdapter rta = new RolesTableAdapter();
     rta.Insert(EmployeeID, role);
 }
 /// <summary>
 /// Gets the roles.
 /// </summary>
 /// <param name="userID">The user ID.</param>
 /// <returns></returns>
 private List<string> getRoles(int userID)
 {
     RolesTableAdapter rta = new RolesTableAdapter();
     var roles = rta.GetDataByUserID(userID);
     return (from p in roles select p.Role).ToList();
 }
 /// <summary>
 /// Removes the user from role.
 /// </summary>
 /// <param name="sessionID">The sessionID of the current session</param>
 /// <param name="EmployeeID">The employee ID of hte employee.</param>
 /// <param name="role">The role the are to be removed from.</param>
 public void RemoveUserFromRole(string sessionID, int EmployeeID, string role)
 {
     RolesTableAdapter rta = new RolesTableAdapter();
     rta.DeleteUserFromRole(EmployeeID, role);
 }