private async void LoginBtn_Click(object sender, EventArgs e) { try { // Gets user if matching username and password exists user = await _repo.GetEmployeeLoginAsync(tbUsername.Text, tbPassword.Text); } catch (System.Data.SqlClient.SqlException) { MessageBox.Show("Couldn't establish connection"); } catch (Exception ex) { MessageBox.Show(ex.Message); } if (user is null) { ShowErrorMessage("Fel login"); return; } await _repo.GetEmployeeTypesByIdAsync(user); // Block access if user has wrong type for selected form if (!user.HasAccess(cbConnectTo.SelectedIndex)) { ShowErrorMessage("Access Denied"); return; } //MessageBox.Show($"Logged in as:\n{user.Username} ID: {user.EmployeeID}\n"); SwitchForm(cbConnectTo.SelectedIndex); user.LoggedIn = true; await _repo.UpdateEmployeeStatusAsync(user); }