protected void OnUserDeleteClicked(object sender, EventArgs e)
    {
        LinkButton lnkItem = (LinkButton)sender;
        string userID = lnkItem.CommandArgument;

        //Check whether this user is being used
        //Delete user's permissions first.
        ParamUserPermissionRepository perRepo = new ParamUserPermissionRepository();
        IList<ParamUserPermission> oldPerList = perRepo.GetPermissionsOfUser(userID);
        foreach (ParamUserPermission deletePer in oldPerList)
        {
            perRepo.DeleteUserPermission(deletePer);
        }

        //Delete user
        ParamUser deleteItem = new ParamUser(userID);
        ParamUserRepository repo = new ParamUserRepository();
        repo.Delete(deleteItem);

        BindGridData();
        gridUsers.DataBind();
    }
 private ParamUser GetUser()
 {
     ParamUser saveItem = new ParamUser();
     saveItem.UserID = txtUserID.Text;
     saveItem.LastName = txtName.Text;
     saveItem.Gender = ddlGenre.SelectedValue;
     saveItem.Email = txtEmail.Text;
     saveItem.Telephone = txtTelephone.Text;
     saveItem.Active = chkActive.Checked;
     if (divChangePassword.Visible)
         saveItem.Password = txtNewPassword.Text;
     else
     {
         if (string.IsNullOrEmpty(Request.QueryString["UserID"]))
             saveItem.Password = txtPassword.Text;
         else
             saveItem.Password = txtPassword.Attributes["value"];
     }
     return saveItem;
 }
    private void SavePermission(ParamUser user)
    {
        ParamUserPermissionRepository perRepo = new ParamUserPermissionRepository();
        IList<ParamUserPermission> oldPerList = perRepo.GetPermissionsOfUser(user.UserID);

        string[] newPerArray = hiddenPermissionList.Value.Split(';');
        if (newPerArray != null && newPerArray.Length > 0)
        {
            for (int i = 0; i < newPerArray.Length; i++)
            {
                if (!string.IsNullOrEmpty(newPerArray[i]))
                {
                    bool isNew = true;
                    foreach (ParamUserPermission oldItem in oldPerList)
                    {
                        if (oldItem.PermissionCode.Trim() == newPerArray[i].Trim())
                        {
                            isNew = false;
                            break;
                        }
                    }
                    if (isNew)
                    {
                        ParamUserPermission newItem = new ParamUserPermission();
                        newItem.UserID = user.UserID;
                        newItem.PermissionCode = newPerArray[i].Trim();
                        perRepo.Insert(newItem);
                    }
                }
            }
        }

        foreach (ParamUserPermission oldItem in oldPerList)
        {
            bool isDelete = true;
            if (newPerArray != null && newPerArray.Length > 0)
            {
                for (int i = 0; i < newPerArray.Length; i++)
                {
                    if (oldItem.PermissionCode.Trim() == newPerArray[i].Trim())
                    {
                        isDelete = false;
                        break;
                    }
                }
            }
            if (isDelete)
                perRepo.DeleteUserPermission(oldItem);
        }
    }
Beispiel #4
0
    private void SaveUserToCookie(ParamUser user)
    {
        HttpCookie loginCookie = new HttpCookie("loginCookie");
        loginCookie.Expires = DateTime.Now.AddDays(7);
        loginCookie.Values.Add("uid", user.UserID);
        loginCookie.Values.Add("pwd", GetMD5Hash(user.Password));

        Response.Cookies.Add(loginCookie);
    }