Note that there are some explanatory texts on larger screens.

plurals
  1. POHow would you refactor this to make it nicer?
    primarykey
    data
    text
    <p>How would you refactor something like this?</p> <pre><code>protected void btnAdd_Click(object sender, EventArgs e) { try { string username = txtUsername.Text.Trim().ToLower(); string password = txtPassword.Text.Trim().ToLower(); string email = txtEmail.Text.Trim().ToLower(); string status = ddlStatus.SelectedValue.Trim(); IUser user = UserFactory.getInstance().createUser(username, password, email,status); if (user.save()) { jsMsgBox("Successfully added new user"); Response.Redirect(ConfigurationManager.AppSettings["AdminLink"], true); } else { jsMsgBox("An error was encountered while trying to add a new user."); } } catch (Exception ex) { jsMsgBox("An Error was encountered while trying to add a new user."); lblInfo.Text = ex.Message; lblInfo.Visible = true; } } protected void btnUpdate_Click(object sender, EventArgs e) { try { string username = txtUsername.Text.Trim().ToLower(); string password = txtPassword.Text.Trim().ToLower(); string email = txtEmail.Text.Trim().ToLower(); int userPK = Int32.Parse(txtUserPK.Text.ToString()); string status = ddlStatus.SelectedValue.Trim(); IUser user = UserFactory.getInstance().createUser(userPK, username, password, email,status); if (user.save()) { jsMsgBox("Successfully updated selected users information."); Response.Redirect(ConfigurationManager.AppSettings["AdminLink"], true); } else { jsMsgBox("An error was encountered while trying to update the selected users information."); } } catch (Exception ex) { jsMsgBox("An Error was encountered while trying to update the selected users information."); lblInfo.Text = ex.Message; lblInfo.Visible = true; } } </code></pre> <p>Take care</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload