protected void btnCreateUserAcc_Click(object sender, EventArgs e) { hideDIV(); //Employee Data Employee employee = new Employee(); //validate fields , set value and check if all madatory values are set. Boolean allMandatoryFieldsSet = validateAndSetEmployeeData(employee); //First is first, check if Employee ID is duplicate or not. EmployeeManager employeeManager = new EmployeeManager(employee); Boolean isEmployeeDuplicate = employeeManager.isEmployeeAlreadyExist(); displayEmployeeDuplicateMessage(isEmployeeDuplicate, employee.EmpID); //Check if all mandatory fields are set and Employee is not duplicate. if (allMandatoryFieldsSet && !isEmployeeDuplicate) { //I think here we have to check wether Employee ID is in database or not // else user is created here and when we need to correct Employee ID and click create user it displays username already exist. MembershipCreateStatus createStatus; MembershipUser newUser = Membership.CreateUser(employee.UserName, "cbe@123", employee.UserName + "@cbe.com.et", "what", "what", true, out createStatus); switch (createStatus) { case MembershipCreateStatus.Success: //set userID for the employee. employee.UserID = (Guid)newUser.ProviderUserKey; //manage Employee transaction using EMployee manager. TransactionResponse response = employeeManager.storeEmployee(); //Transaction is successful if (response.isSuccessful()) { //show sucessfull message. msgPanel.Visible = true; SucessDIV.Visible = true; lblSuccessMessage.Text = "The user account is successfully created! " + "Employee ID: " + employee.EmpID + " user name: " + employee.UserName; btnCreateUserAcc.Visible = false; btnAddNew.Visible = true; //resetComponents(); } else { //display this message to the user. hideDIV(); msgPanel.Visible = true; ErroroDIV.Visible = true; lblErrorMsg.Text = response.getMessage() + "(" + response.getErrorCode() + ") "; } break; case MembershipCreateStatus.DuplicateUserName: hideDIV(); msgPanel.Visible = true; WarnDIV.Visible = true; lblWarningMsg.Text = "There already exists a user with this username."; break; case MembershipCreateStatus.DuplicateEmail: hideDIV(); msgPanel.Visible = true; WarnDIV.Visible = true; lblWarningMsg.Text = "There already exists a user with this email address."; break; case MembershipCreateStatus.InvalidEmail: hideDIV(); msgPanel.Visible = true; WarnDIV.Visible = true; lblWarningMsg.Text = "There email address you provided in invalid."; break; case MembershipCreateStatus.InvalidAnswer: hideDIV(); msgPanel.Visible = true; WarnDIV.Visible = true; lblWarningMsg.Text = "There security answer was invalid."; break; case MembershipCreateStatus.InvalidPassword: hideDIV(); msgPanel.Visible = true; WarnDIV.Visible = true; lblWarningMsg.Text = "The password you provided is invalid. It must be seven characters long and have at least one non-alphanumeric character."; break; default: hideDIV(); msgPanel.Visible = true; WarnDIV.Visible = true; lblWarningMsg.Text = "There was an unknown error; the user account was NOT created."; break; } } }