private void btnLogin_Click(object sender, EventArgs e) { if (String.IsNullOrWhiteSpace(txtEmail.Text) || string.IsNullOrWhiteSpace(txtPassword.Text)) { lblError.Text = "Either email or password is missing"; return; } if (!txtEmail.Text.Contains("@")) { lblError.Text = "Invalid email address"; return; } CustomerEmail email = new CustomerEmail { Email = txtEmail.Text, password = txtPassword.Text }; ProductContext context = new ProductContext(); var result = context.VerifyLoginDetails(email); var isCustomerValid = result.Item1; if (!isCustomerValid) { ConnectionManager.IsAuthenticated = false; ConnectionManager.ActiveCustomerId = -1; lblError.Text = "Invalid customer details. Please try again."; } else { ConnectionManager.IsAuthenticated = true; ConnectionManager.ActiveCustomerId = result.Item2.customerID; // navigate to home page OnSucessfullLogin?.Invoke(); } }
private void btnRegister_Click(object sender, EventArgs e) { lblError.Text = ""; if (string.IsNullOrWhiteSpace(txtFirstName.Text)) { lblError.Text = "First name can not be empty. Please try again."; return; } if (string.IsNullOrWhiteSpace(txtLastName.Text)) { lblError.Text = "Last name can not be empty. Please try again."; return; } // check phone number if (!IsPhoneNumberValid(txtPhoneNumber.Text)) { lblError.Text = "Entered phone number is invalid. Please try again."; return; } if (!IsValidEmail(txtEmail.Text)) { lblError.Text = " Invalid email address. Please try again."; return; } if (string.IsNullOrWhiteSpace(txtPassword.Text)) { lblError.Text = "Password can not be empty. Please try again."; return; } if (string.IsNullOrWhiteSpace(txtConfirmPassword.Text)) { lblError.Text = "Confirm Password can not be empty. Please try again."; return; } if (!txtPassword.Text.Equals(txtConfirmPassword.Text)) { lblError.Text = "Password mismatch. Please try again."; return; } int customerId = (new Random()).Next(); customerPhoneNumber phoneNo = new customerPhoneNumber { PhoneNumber = txtPhoneNumber.Text }; CustomerEmail email = new CustomerEmail { Email = txtEmail.Text, password = txtConfirmPassword.Text }; Customer customer = new Customer { customerID = customerId, customerFN = txtFirstName.Text, customerLN = txtLastName.Text, customerPhoneNumber = phoneNo, customerEmail = email, Created_date = DateTime.Now }; ProductContext context = new ProductContext(); bool isRegistered = context.RegisterCustomer(customer); if (!isRegistered) { // if registration is failed lblError.Text = "Email id already exists. Please try again."; return; } // navigate to home page OnSucessfullRegistration?.Invoke(); }