private async void BtnRegister_Click(object sender, EventArgs e) { if (this.ValidateChildren()) { var osobaRequest = new Wellness.Model.Requests.OsobaInsertRequest(); osobaRequest.Ime = txtIme.Text; osobaRequest.Prezime = txtPrezime.Text; osobaRequest.DatumRodenja = dtpDatumRodenja.Value; osobaRequest.Spol = (cbSpol.SelectedValue.ToString().Substring(0, 1).ToUpper()); osobaRequest.GradId = (int)cbMjestoBoravka.SelectedValue; osobaRequest.Jmbg = txtJMBG.Text; osobaRequest.Email = txtEmail.Text; osobaRequest.BrojTelefona = txtBrojTelefona.Text; osobaRequest.KorisnickoIme = txtUserName.Text; osobaRequest.UlogaId = (int)cbUloga.SelectedValue; Wellness.Model.Osoba osoba = null; Wellness.Model.Radnik radnik = null; if (_id == null) { osobaRequest.Password = txtPassword.Text; osobaRequest.PasswordPotvrda = txtPasswordPotvrda.Text; osoba = await _apiService.Insert <Wellness.Model.Osoba>(osobaRequest); if (osoba.Uloga.Naziv != "Clan") { var radnikRequest = new Wellness.Model.Requests.RadnikInsertRequest() { Satnica = decimal.Parse(txtSatnica.Text), OsobaId = osoba.Id }; radnik = await _apiService_Radnik.Insert <Wellness.Model.Radnik>(radnikRequest); if (osoba.Uloga.Naziv == "Trener") { var trenerRequest = new TrenerInsertRequest() { Specializacija = txtSpecijalizacija.Text, RadnikId = radnik.Id }; var trener = await _apiService_Trener.Insert <Model.Trener>(trenerRequest); } } else { var clanInsertRequest = new ClanInsertRequest() { Aktivan = true, DatumRegistracije = DateTime.Now, OsobaId = osoba.Id }; var clan = await _apiService_Clan.Insert <Wellness.Model.Clan>(clanInsertRequest); } MessageBox.Show("Uspjesno ste dodali novog korisnika", "success", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { osoba = await _apiService.Update <Wellness.Model.Osoba>(_id, osobaRequest); if (osoba.Uloga.Naziv != "Clan") { var radnikRequest = new Wellness.Model.Requests.RadnikInsertRequest() { Satnica = decimal.Parse(txtSatnica.Text), OsobaId = osoba.Id }; var radnikSearchRequest = new RadnikSearchRequest() { OsobaId = radnikRequest.OsobaId }; var radnikList = await _apiService_Radnik.Get <List <Wellness.Model.Radnik> >(radnikSearchRequest); radnik = await _apiService_Radnik.Update <Wellness.Model.Radnik>(radnikList[0].Id, radnikRequest); if (osoba.Uloga.Naziv == "Trener") { var trenerRequest = new TrenerInsertRequest() { RadnikId = radnik.Id, Specializacija = txtSpecijalizacija.Text }; var trenerList = await _apiService_Trener.Get <List <Model.Trener> >(new TrenerSearchRequest() { OsobaId = osoba.Id }); var trener = _apiService_Trener.Update <Model.Trener>(trenerList[0].Id, trenerRequest); } } MessageBox.Show("Uspjesno ste ažurirali korisnika", "success", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } }
//treba implementirat trenera u apiu private async void FrmRadniciDetalji_Load(object sender, EventArgs e) { if (_id.HasValue) { lblPotvrdaSifre.Visible = false; txtPasswordPotvrda.Visible = false; btnPromjeniSifru.Location = new Point(178, 441); } else { btnPromjeniSifru.Visible = false; } var spol = new List <Spol>(); spol.Add(new Spol() { spol = "M" }); spol.Add(new Spol() { spol = "Z" }); cbSpol.DataSource = spol; cbSpol.ValueMember = "spol"; cbSpol.DisplayMember = "spol"; cbSpol.DropDownStyle = ComboBoxStyle.DropDownList; //------------------Grad List <Model.Grad> gradovi = await _apiService_Grad.Get <List <Model.Grad> >(null); cbMjestoBoravka.DataSource = gradovi; cbMjestoBoravka.DisplayMember = "Grad1"; cbMjestoBoravka.ValueMember = "id"; cbMjestoBoravka.DropDownStyle = ComboBoxStyle.DropDownList; //------------------ //------------------TipKorisnika var uloge = await _apiService_Uloga.Get <List <Wellness.Model.Uloga> >(null); cbUloga.DataSource = uloge; cbUloga.DisplayMember = "Naziv"; cbUloga.ValueMember = "Id"; cbUloga.DropDownStyle = ComboBoxStyle.DropDownList; if (calledByRecepcionar == true) { cbUloga.SelectedValue = 4; cbUloga.Enabled = false; } //------------------ Wellness.Model.Radnik Radnik = null; if (_id != null) { var Osoba = await _apiService.GetById <Wellness.Model.Osoba>(_id); if (Osoba.Ime != null) { txtIme.Text = Osoba.Ime; } if (Osoba.Prezime != null) { txtPrezime.Text = Osoba.Prezime; } if (Osoba.Spol != null) { cbSpol.SelectedValue = Osoba.Spol; } if (Osoba.GradId != null) { cbMjestoBoravka.SelectedValue = Osoba.GradId; } if (Osoba.Jmbg != null) { txtJMBG.Text = Osoba.Jmbg; } if (Osoba.Email != null) { txtEmail.Text = Osoba.Email; } if (Osoba.BrojTelefona != null) { txtBrojTelefona.Text = Osoba.BrojTelefona; } if (Osoba.KorisnickoIme != null) { txtUserName.Text = Osoba.KorisnickoIme; } txtPassword.Enabled = false; txtPasswordPotvrda.Enabled = false; cbUloga.SelectedValue = Osoba.UlogaId; cbUloga.DropDownStyle = ComboBoxStyle.DropDownList; cbSpol.DropDownStyle = ComboBoxStyle.DropDownList; cbMjestoBoravka.DropDownStyle = ComboBoxStyle.DropDownList; if ((int)cbUloga.SelectedValue == 4) { txtSpecijalizacija.Visible = false; lblSpecijalizacija.Visible = false; txtSatnica.Visible = false; lblSatnica.Visible = false; } else { var radnikList = await _apiService_Radnik.Get <List <Wellness.Model.Radnik> >(new RadnikSearchRequest() { OsobaId = Osoba.Id }); Radnik = radnikList[0]; txtSatnica.Visible = true; lblSatnica.Visible = true; txtSatnica.Value = Math.Round(Radnik.Satnica, 2); } if ((int)cbUloga.SelectedValue == 3) { txtSpecijalizacija.Visible = true; txtSpecijalizacija.Enabled = true; lblSpecijalizacija.Visible = true; isTrener = true; var trenerList = await _apiService_Trener.Get <List <Wellness.Model.Trener> >(new TrenerSearchRequest() { OsobaId = Osoba.Id }); var Trener = trenerList[0]; txtSpecijalizacija.Text = Trener.Specializacija; } else { txtSpecijalizacija.Visible = false; txtSpecijalizacija.Enabled = false; lblSpecijalizacija.Visible = false; isTrener = false; } if ((int)cbUloga.SelectedValue != 4) { txtSatnica.Visible = true; txtSatnica.Enabled = true; lblSatnica.Visible = true; isRadnik = true; } else { txtSatnica.Visible = false; txtSatnica.Enabled = false; lblSatnica.Visible = false; isRadnik = false; } cbUloga.Enabled = false; } }