public async Task Auth() { try { var t = await _service.Auth(Username, Password, _selectedVrstaProizvoda.UlogaId); int roleId = t.Last; int userId = t.First; ULOGA u = await _service_uloga.GetById <ULOGA>(roleId); if (u.Naziv == "Administrator") { Application.Current.MainPage = new AdminPage(roleId, userId); } else if (u.Naziv == "Student") { Application.Current.MainPage = new StudPage(roleId, userId); } else if (u.Naziv == "Profesor") { Application.Current.MainPage = new ProfPage(userId, roleId); } } catch (NullReferenceException e) { await Application.Current.MainPage.DisplayAlert("Greška", "Niste unijeli ispravne podatke", "OK"); } }
private async void btnPrijava_Click(object sender, EventArgs e) { if (txtUsername.Text != "" && txtPass.Text != "" && ((int)cbRole.SelectedValue != 0)) { string username = txtUsername.Text; string pass = txtPass.Text; int ulogaId = (int)cbRole.SelectedValue; try { var id = await _service_auth.Auth(username, pass, ulogaId); ULOGA u = await _service_uloga.GetById <ULOGA>(ulogaId); if (id != null) { this.MinimizeBox = true; if (u.Naziv == "Administrator") { frmAdmin frm = new frmAdmin((int)id[0]); frm.Show(); } else if (u.Naziv == "Student") { frmStud frm = new frmStud((int)id[0]); frm.Show(); } else if (u.Naziv == "Profesor") { frmProf frm = new frmProf((int)id[0]); frm.Show(); } } //else if (id == null) //{ // MessageBox.Show("Unijeli ste pogrešne podatke", "Upozorenje", MessageBoxButtons.OK, MessageBoxIcon.Error); //} } catch (Exception except) { MessageBox.Show("Molimo unesite ispravne podatke", "Upozorenje", MessageBoxButtons.OK, MessageBoxIcon.Error); }; } else { MessageBox.Show("Molimo unesite ispravne podatke", "Upozorenje", MessageBoxButtons.OK, MessageBoxIcon.Error); } }