private async void btnSnimi_Click(object sender, EventArgs e) { if (this.ValidateChildren()) { // txtSlikaInput = Convert.ToBase64String(circleButton1.Image.); byte[] bytes = Encoding.ASCII.GetBytes(txtSlikaInput.Text); Check2(); if (txtOcjena.Text == "") { txtOcjena.Text = "0"; } if (txtLat.Text == "") { txtLat.Text = "0"; } if (txtLong.Text == "") { txtLong.Text = "0"; } double number = 0; bool dialog = double.TryParse(txtOcjena.Text.ToString(), out number); if (dialog == false) { MessageBoxButtons buttons = MessageBoxButtons.YesNo; DialogResult dialog1 = MessageBox.Show("Molimo ponovo unesite ocjenu", "Abort operation", buttons); if (dialog1 == DialogResult.Yes) { } else { // Do something } } else { var request = new ApartmaniUpsertRequest { Naziv = txtNazivA.Text, Lokacija = txtLok.Text, Latitude = double.Parse(txtLat.Text), Slika = bytes, Longitude = double.Parse(txtLong.Text), KategorijaApartmana = cmbKat.SelectedItem.ToString(), KategorijaId = 5, Wifi = b1, Bazen = b2, Parking = b3, Tv = b4, Klima = b5, AparatZaKafu = b6, Ocjena = double.Parse(txtOcjena.Text) }; if (cmbGodine.SelectedItem != null) { request.GodinaIzgradnje = int.Parse(cmbGodine.SelectedItem.ToString()); } if (openFileDialog1.FileName.Length != 0) { request.PutanjaSlike = txtSlikaInput.Text; } if (_id != null || _id != 0) { if (APIService.isUpdate == true && APIService.isDelete == false) { await _apartmani.Update <Model.Apartmani>(_id, request); MessageBox.Show("Uspješno ste modificirali atribute apartmana!"); } else if (APIService.isUpdate == false && APIService.isDelete == true) { await _apartmani.Delete((int)_id); MessageBox.Show("Uspješno ste obrisali apartman!"); } } FreeUp(); await LoadApartmani(); } } }
private async void btnSnimi_Click(object sender, EventArgs e) { if (txtNazivA.Text == "") { MessageBox.Show("Molimo pokušajte ponovo sa unosom", "Nedovoljno informacija", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } if (txtLok.Text == "") { MessageBox.Show("Objekat mora imati lokaciju", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } else { var request = new ApartmaniUpsertRequest { Naziv = txtNazivA.Text, Lokacija = txtLok.Text, Latitude = latitude, Longitude = longitude, KategorijaId = 5, PutanjaSlike = openFileDialog1.FileName }; request.GodinaIzgradnje = int.Parse(dateTimePicker1.Value.Year.ToString()); request.Ocjena = double.Parse(txtOcjena.Text); request.Slika = slika; request.KategorijaApartmana = comboBox1.SelectedItem.ToString(); if (button1.BackColor == Color.DarkGreen) { request.Wifi = true; } else { request.Wifi = false; } if (bb3.BackColor == Color.DarkGreen) { request.Bazen = true; } else { request.Bazen = false; } if (bb5.BackColor == Color.DarkGreen) { request.Parking = true; } else { request.Parking = false; } if (bb7.BackColor == Color.DarkGreen) { request.Tv = true; } else { request.Tv = false; } if (bb9.BackColor == Color.DarkGreen) { request.Klima = true; } else { request.Klima = false; } if (bb11.BackColor == Color.DarkGreen) { request.AparatZaKafu = true; } else { request.AparatZaKafu = false; } if (request != null) { try { await _apartmani.Insert <Model.Apartmani>(request); MessageBox.Show("Uspješno ste dodali apartman!"); Obrisi(); } catch { MessageBox.Show("Greška prilikom dodavanja!"); } } } }