/// <summary> /// Called when the Update button is clicked by the user /// </summary> protected void saveUserDetailsButton_Click(object sender, EventArgs e) { int id = Convert.ToInt32(Request.QueryString[Constants.ID]); var userData = new AppDataContract(id, SSN.Text, FirstName.Text, LastName.Text, Phone.Text.Replace("-", ""), DateTime.Today); var service = new OmicronService.OmicronServiceClient(); bool userOkay = false; try { userOkay = service.ChangeUserData(userData, (Guid)Session[Constants.USER_TOKEN]); } catch { Response.Redirect(Constants.LOGIN_PAGE); } if (userOkay) { Response.Redirect(Constants.VIEW_PAGE_PARTIAL + id); } else { Response.Redirect(Constants.LOGIN_PAGE); } }
/// <summary> /// Changes the users data with the new data. /// </summary> /// <param name="userData">The updated data</param> /// <param name="GUID">The user token to authenticate this action</param> /// <returns>True if the user was updated</returns> public bool ChangeUserData(AppDataContract userData, Guid GUID) { UserToken user = getUserFromToken(GUID); if (user.Type == UserType.USER && user.ID == userData.ID) { openConnection(); makeCommand(string.Format("UPDATE {0} " + "SET {1}=@firstName, {2}=@lastName, {3}=@phone " + "WHERE {4}=@userId", Constants.TABLE_APP_DATA, Constants.FIRST_NAME, Constants.LAST_NAME, Constants.PHONE, Constants.ID), new PreparedData(SqlDbType.VarChar, userData.FirstName, 50), new PreparedData(SqlDbType.VarChar, userData.LastName, 50), new PreparedData(SqlDbType.Char, userData.Phone.Replace("-", ""), 10), new PreparedData(SqlDbType.Int, userData.ID) ).ExecuteNonQuery(); closeConnection(); return true; } return false; }
private void placeUserData(AppDataContract userData) { bool canChange = userData.Changeable; SSN.Text = userData.SSN; setEditability(SSN, "SSN", canChange); FirstName.Text = userData.FirstName; setEditability(FirstName, "FirstName", canChange); LastName.Text = userData.LastName; setEditability(LastName, "LastName", canChange); Phone.Text = userData.Phone; setEditability(Phone, "Phone", canChange); DateSubmitted.Text = userData.DateSubmitted.ToShortDateString(); setEditability(DateSubmitted, "DateSubmitted", canChange); bool isAdmin = (bool)Session[Constants.IS_ADMIN]; returnAdminLink.Visible = isAdmin; saveUserDetailsButton.Visible = !isAdmin; }