Exemplo n.º 1
0
        private async void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                APIService.Username = txtUsername.Text;
                APIService.Password = txtPassword.Text;
                await serviceKorisnik.Get <dynamic>(null); //request na server


                var pretragaKorisnika = await serviceKorisnik.Get <List <MKorisnik> >(new KorisnikSearchRequest { KorisnickoIme = APIService.Username });

                Global.prijavljeniKorisnik = pretragaKorisnika.FirstOrDefault();

                var pretragaRestorana = await serviceRestoran.Get <List <MKorisnikRestoran> >(new KorisnikRestoranSearchRequest { KorisnikId = Global.prijavljeniKorisnik.KorisnikId });

                Global.prijavljeniRestoran = pretragaRestorana.FirstOrDefault();
                this.Hide();

                frmIndex frm = new frmIndex();

                frm.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Autentifikacija", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private async void btnClick_Click(object sender, EventArgs e)
        {
            try
            {
                APIService.Username = txtUsername.Text;
                APIService.Password = txtPassword.Text;

                if (string.IsNullOrEmpty(txtUsername.Text) || string.IsNullOrEmpty(txtPassword.Text))
                {
                    MessageBox.Show("All fields are required! Try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                var request = new CustomerSearchRequest {
                    Username = txtUsername.Text
                };
                var customer = await _apiService.Get <List <Data.Model.Customer> >(request);

                if (customer.Count == 0)
                {
                    MessageBox.Show("Customer with this credentials don't exist! Try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    frmIndex frm = new frmIndex();
                    frm.Show();
                    this.Hide();
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, "Wrong username or password", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private async void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                APIService.Username = txtUsername.Text;
                APIService.Password = txtPassword.Text;
                List <AdministratorLogin> list = await _adminService.Get <List <AdministratorLogin> >(new AdminSearchRequest()
                {
                    AdminName = txtUsername.Text
                });

                if (list.Count == 0)
                {
                    MessageBox.Show("Wrong username or password!");
                    APIService.Username = "";
                    APIService.Password = "";
                    return;
                }
                else
                {
                    var frmIndex = new frmIndex();
                    frmIndex.Show();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Authentication", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }