public int UpdateTeretno(string id, Teretno r) { try { ISession s = DataLayer.GetSession(); IQuery query = s.CreateQuery("select r from Teretno r where r.RegOznaka = " + id); Teretno vozilo = query.UniqueResult <Teretno>(); vozilo.Boja = r.Boja; vozilo.Gorivo = r.Gorivo; vozilo.ZapreminaMotora = r.ZapreminaMotora; vozilo.Nosivost = r.Nosivost; vozilo.BrojOsovina = r.BrojOsovina; s.SaveOrUpdate(vozilo); s.Flush(); s.Close(); return(1); } catch (Exception exc) { System.Windows.Forms.MessageBox.Show(exc.Message); return(-1); } }
public TeretnoView GetTeretno(string regozn) { ISession s = DataLayer.GetSession(); Teretno vozilo = s.Query <Teretno>().Where(e => e.RegOznaka == regozn).Select(p => p).FirstOrDefault(); TeretnoView v = new TeretnoView(vozilo); return(v); }
public TeretnoView(Teretno t) { this.RegOznaka = t.RegOznaka; this.Gorivo = t.Gorivo; this.Boja = t.Boja; this.ZapreminaMotora = t.ZapreminaMotora; this.BrojOsovina = t.BrojOsovina; this.Nosivost = t.Nosivost; this.Deonice = t.Deonice.Count; }
public TeretnoView VratiTeretnoView(int id) { ISession s = DataLayer.GetSession(); Teretno vozilo = s.Query <Teretno>() .Where(v => v.id == id).Select(p => p).FirstOrDefault(); if (vozilo == null) { return(new TeretnoView()); } return(new TeretnoView(vozilo)); }
public int AddTeretno(Teretno v) { try { ISession s = DataLayer.GetSession(); s.Save(v); s.Flush(); s.Close(); return(1); } catch (Exception e) { return(-1); } }
public int RemoveTeretno(string reg) { try { ISession s = DataLayer.GetSession(); Teretno n = s.Load <Teretno>(reg); s.Delete(n); s.Flush(); s.Close(); return(1); } catch (Exception e) { return(-1); } }
public int ObrisiTeretnoVozilo(int id) { try { ISession s = DataLayer.GetSession(); Teretno v = s.Load <Teretno>(id); s.Delete(v); s.Flush(); s.Close(); return(1); } catch (Exception ec) { return(-1); } }
public TeretnoView(Teretno p) { id = p.id; brojSasije = p.brojSasije; boja = p.boja; brojMotora = p.brojMotora; gorivo = p.gorivo; modelVozila = p.modelVozila; kubikaza = p.kubikaza; datumUvoza = p.datumUvoza; datumKupovine = p.datumKupovine; poznato = p.poznato; opisProblema = p.opisProblema; ime = p.ime; prezime = p.prezime; telefon = p.telefon; tipVozila = p.tipVozila; registarskiBroj = p.registarskiBroj; godinaProizvodnje = p.godinaProizvodnje; tipProstora = p.tipProstora; nosivost = p.nosivost; }
private void btn_sacuvaj_Click(object sender, EventArgs e) { try { //kreira novog kupca if (novoVozilo) { if (string.IsNullOrEmpty(txt_tip_vozila.Text)) { MessageBox.Show("Polje Tip Vozila ne sme biti prazno!", "Upozorenje", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } ISession session = DataLayer.GetSession(); switch (cb_prikaz.Text) { case "putnicko": { Putnicko vozilo = new Putnicko(); vozilo.boja = txt_boja.Text; if (string.IsNullOrEmpty(txt_br_motora.Text)) { vozilo.brojMotora = null; } else { vozilo.brojMotora = Double.Parse(txt_br_motora.Text); } vozilo.brojPutnika = int.Parse(txt_br_putnika.Text); if (string.IsNullOrEmpty(txt_br_sasije.Text)) { vozilo.brojSasije = null; } else { vozilo.brojSasije = Double.Parse(txt_br_sasije.Text); } vozilo.datumKupovine = DateTime.Parse(dtp_datum_kupovine.Value.ToString()); vozilo.datumUvoza = DateTime.Parse(dtp_datum_uvoza.Value.ToString()); if (string.IsNullOrEmpty(txt_godina_proizvodnje.Text)) { vozilo.godinaProizvodnje = null; } else { vozilo.godinaProizvodnje = int.Parse(txt_godina_proizvodnje.Text); } vozilo.gorivo = txt_gorivo.Text; vozilo.ime = txt_ime.Text; vozilo.prezime = txt_prezime.Text; if (string.IsNullOrEmpty(txt_telefon.Text)) { vozilo.telefon = null; } else { vozilo.telefon = long.Parse(txt_telefon.Text); } if (string.IsNullOrEmpty(txt_kubikaza.Text)) { vozilo.kubikaza = null; } else { vozilo.kubikaza = float.Parse(txt_kubikaza.Text); } if (!string.IsNullOrEmpty(txt_id_kupac.Text)) { var kupac = (from kpc in session.Query <Kupac>() where kpc.id == int.Parse(txt_id_kupac.Text) select kpc).SingleOrDefault(); vozilo.kupac = kupac; } else { vozilo.kupac = null; } vozilo.modelVozila = txt_model_vozila.Text; vozilo.opisProblema = txt_opis_problema.Text; vozilo.poznato = txt_poznato.Text; if (string.IsNullOrEmpty(txt_registarski_broj.Text)) { vozilo.registarskiBroj = null; } else { vozilo.registarskiBroj = long.Parse(txt_registarski_broj.Text); } if (!string.IsNullOrEmpty(txt_id_salon.Text)) { var salon = (from sln in session.Query <Salon>() where sln.idSalon == int.Parse(txt_id_salon.Text) select sln).SingleOrDefault(); vozilo.salon = salon; } else { vozilo.salon = null; } if (!string.IsNullOrEmpty(txt_id_servis.Text)) { var servis = (from srv in session.Query <Servis>() where srv.id == int.Parse(txt_id_servis.Text) select srv).SingleOrDefault(); vozilo.servis = servis; } else { vozilo.servis = null; } vozilo.tipVozila = txt_tip_vozila.Text; session.Save(vozilo); session.Flush(); session.Close(); GetData("putnicko"); novoVozilo = false; break; } case "teretno": { Teretno vozilo = new Teretno(); vozilo.boja = txt_boja.Text; if (string.IsNullOrEmpty(txt_br_motora.Text)) { vozilo.brojMotora = null; } else { vozilo.brojMotora = Double.Parse(txt_br_motora.Text); } if (string.IsNullOrEmpty(txt_br_sasije.Text)) { vozilo.brojSasije = null; } else { vozilo.brojSasije = Double.Parse(txt_br_sasije.Text); } vozilo.datumKupovine = DateTime.Parse(dtp_datum_kupovine.Value.ToString()); vozilo.datumUvoza = DateTime.Parse(dtp_datum_uvoza.Value.ToString()); if (string.IsNullOrEmpty(txt_godina_proizvodnje.Text)) { vozilo.godinaProizvodnje = null; } else { vozilo.godinaProizvodnje = int.Parse(txt_godina_proizvodnje.Text); } vozilo.gorivo = txt_gorivo.Text; vozilo.ime = txt_ime.Text; vozilo.prezime = txt_prezime.Text; if (string.IsNullOrEmpty(txt_telefon.Text)) { vozilo.telefon = null; } else { vozilo.telefon = long.Parse(txt_telefon.Text); } if (string.IsNullOrEmpty(txt_kubikaza.Text)) { vozilo.kubikaza = null; } else { vozilo.kubikaza = float.Parse(txt_kubikaza.Text); } if (!string.IsNullOrEmpty(txt_id_kupac.Text)) { var kupac = (from kpc in session.Query <Kupac>() where kpc.id == int.Parse(txt_id_kupac.Text) select kpc).SingleOrDefault(); vozilo.kupac = kupac; } else { vozilo.kupac = null; } vozilo.modelVozila = txt_model_vozila.Text; vozilo.nosivost = Double.Parse(txt_nosivost.Text); vozilo.opisProblema = txt_opis_problema.Text; vozilo.poznato = txt_poznato.Text; if (string.IsNullOrEmpty(txt_registarski_broj.Text)) { vozilo.registarskiBroj = null; } else { vozilo.registarskiBroj = long.Parse(txt_registarski_broj.Text); } if (!string.IsNullOrEmpty(txt_id_salon.Text)) { var salon = (from sln in session.Query <Salon>() where sln.idSalon == int.Parse(txt_id_salon.Text) select sln).SingleOrDefault(); vozilo.salon = salon; } else { vozilo.salon = null; } if (!string.IsNullOrEmpty(txt_id_servis.Text)) { var servis = (from srv in session.Query <Servis>() where srv.id == int.Parse(txt_id_servis.Text) select srv).SingleOrDefault(); vozilo.servis = servis; } else { vozilo.servis = null; } vozilo.tipProstora = txt_tip_prostora.Text; vozilo.tipVozila = txt_tip_vozila.Text; session.Save(vozilo); session.Flush(); session.Close(); GetData("teretno"); novoVozilo = false; break; } } } //azurira postojeceg kupca else { ISession session = DataLayer.GetSession(); int id = int.Parse(dgvVozilo.SelectedRows[0].Cells[0].Value.ToString()); switch (cb_prikaz.Text) { case "putnicko": { Putnicko vozilo = session.Load <Putnicko>(id); vozilo.boja = txt_boja.Text; if (string.IsNullOrEmpty(txt_br_motora.Text)) { vozilo.brojMotora = null; } else { vozilo.brojMotora = Double.Parse(txt_br_motora.Text); } vozilo.brojPutnika = int.Parse(txt_br_putnika.Text); if (string.IsNullOrEmpty(txt_br_sasije.Text)) { vozilo.brojSasije = null; } else { vozilo.brojSasije = Double.Parse(txt_br_sasije.Text); } vozilo.datumKupovine = DateTime.Parse(dtp_datum_kupovine.Value.ToString()); vozilo.datumUvoza = DateTime.Parse(dtp_datum_uvoza.Value.ToString()); if (string.IsNullOrEmpty(txt_godina_proizvodnje.Text)) { vozilo.godinaProizvodnje = null; } else { vozilo.godinaProizvodnje = int.Parse(txt_godina_proizvodnje.Text); } vozilo.gorivo = txt_gorivo.Text; vozilo.ime = txt_ime.Text; vozilo.prezime = txt_prezime.Text; if (string.IsNullOrEmpty(txt_telefon.Text)) { vozilo.telefon = null; } else { vozilo.telefon = long.Parse(txt_telefon.Text); } if (string.IsNullOrEmpty(txt_kubikaza.Text)) { vozilo.kubikaza = null; } else { vozilo.kubikaza = float.Parse(txt_kubikaza.Text); } if (!string.IsNullOrEmpty(txt_id_kupac.Text)) { var kupac = (from kpc in session.Query <Kupac>() where kpc.id == int.Parse(txt_id_kupac.Text) select kpc).SingleOrDefault(); vozilo.kupac = kupac; } else { vozilo.kupac = null; } vozilo.modelVozila = txt_model_vozila.Text; vozilo.opisProblema = txt_opis_problema.Text; vozilo.poznato = txt_poznato.Text; if (string.IsNullOrEmpty(txt_registarski_broj.Text)) { vozilo.registarskiBroj = null; } else { vozilo.registarskiBroj = long.Parse(txt_registarski_broj.Text); } if (!string.IsNullOrEmpty(txt_id_salon.Text)) { var salon = (from sln in session.Query <Salon>() where sln.idSalon == int.Parse(txt_id_salon.Text) select sln).SingleOrDefault(); vozilo.salon = salon; } else { vozilo.salon = null; } if (!string.IsNullOrEmpty(txt_id_servis.Text)) { var servis = (from srv in session.Query <Servis>() where srv.id == int.Parse(txt_id_servis.Text) select srv).SingleOrDefault(); vozilo.servis = servis; } else { vozilo.servis = null; } vozilo.tipVozila = txt_tip_vozila.Text; session.SaveOrUpdate(vozilo); session.Flush(); session.Close(); GetData("putnicko"); novoVozilo = false; break; } case "teretno": { Teretno vozilo = session.Load <Teretno>(id); vozilo.boja = txt_boja.Text; if (string.IsNullOrEmpty(txt_br_motora.Text)) { vozilo.brojMotora = null; } else { vozilo.brojMotora = Double.Parse(txt_br_motora.Text); } if (string.IsNullOrEmpty(txt_br_sasije.Text)) { vozilo.brojSasije = null; } else { vozilo.brojSasije = Double.Parse(txt_br_sasije.Text); } vozilo.datumKupovine = DateTime.Parse(dtp_datum_kupovine.Value.ToString()); vozilo.datumUvoza = DateTime.Parse(dtp_datum_uvoza.Value.ToString()); if (string.IsNullOrEmpty(txt_godina_proizvodnje.Text)) { vozilo.godinaProizvodnje = null; } else { vozilo.godinaProizvodnje = int.Parse(txt_godina_proizvodnje.Text); } vozilo.gorivo = txt_gorivo.Text; vozilo.ime = txt_ime.Text; vozilo.prezime = txt_prezime.Text; if (string.IsNullOrEmpty(txt_telefon.Text)) { vozilo.telefon = null; } else { vozilo.telefon = long.Parse(txt_telefon.Text); } if (string.IsNullOrEmpty(txt_kubikaza.Text)) { vozilo.kubikaza = null; } else { vozilo.kubikaza = float.Parse(txt_kubikaza.Text); } if (!string.IsNullOrEmpty(txt_id_kupac.Text)) { var kupac = (from kpc in session.Query <Kupac>() where kpc.id == int.Parse(txt_id_kupac.Text) select kpc).SingleOrDefault(); vozilo.kupac = kupac; } else { vozilo.kupac = null; } vozilo.modelVozila = txt_model_vozila.Text; vozilo.nosivost = Double.Parse(txt_nosivost.Text); vozilo.opisProblema = txt_opis_problema.Text; vozilo.poznato = txt_poznato.Text; if (string.IsNullOrEmpty(txt_registarski_broj.Text)) { vozilo.registarskiBroj = null; } else { vozilo.registarskiBroj = long.Parse(txt_registarski_broj.Text); } if (!string.IsNullOrEmpty(txt_id_salon.Text)) { var salon = (from sln in session.Query <Salon>() where sln.idSalon == int.Parse(txt_id_salon.Text) select sln).SingleOrDefault(); vozilo.salon = salon; } else { vozilo.salon = null; } if (!string.IsNullOrEmpty(txt_id_servis.Text)) { var servis = (from srv in session.Query <Servis>() where srv.id == int.Parse(txt_id_servis.Text) select srv).SingleOrDefault(); vozilo.servis = servis; } else { vozilo.servis = null; } vozilo.tipProstora = txt_tip_prostora.Text; vozilo.tipVozila = txt_tip_vozila.Text; session.SaveOrUpdate(vozilo); session.Flush(); session.Close(); GetData("teretno"); novoVozilo = false; break; } } } } catch (Exception catchException) { MessageBox.Show(catchException.Message + catchException.InnerException, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
// PUT api/teretno/5 public int Put(string id, [FromBody] Teretno value) { DataProvider provider = new DataProvider(); return(provider.UpdateTeretno(id, value)); }
// POST api/teretno public int Post([FromBody] Teretno value) { DataProvider dp = new DataProvider(); return(dp.AddTeretno(value)); }