public static void DodajUlicu(UlicaView c) { try { ISession s = DataLayer.GetSession(); var ulica = new Ulica(); var Pozornik = s.Get <PozornikPolicajac>(c.Policajac.PolicajacId); if (Pozornik == null) { return; } ulica.Policajac = Pozornik; ulica.Naziv = c.Naziv; s.Save(ulica); s.Flush(); s.Close(); } catch (Exception e) { Console.WriteLine(e); throw; } }
public static List <UlicaView> VratiSveUlice(int id) { var ulice = new List <UlicaView>(); try { ISession s = DataLayer.GetSession(); IEnumerable <Ulica> sveUlice = from c in s.Query <Ulica>() where c.Policajac.PolicajacId == id select c; foreach (var ulica in sveUlice) { var tmp = new UlicaView(ulica); tmp.Policajac = new PozornikPolicajacView(ulica.Policajac); ulice.Add(tmp); } } catch (Exception e) { Console.WriteLine(e); throw; } return(ulice); }
public static List <UlicaView> VratiSveUlice() { List <UlicaView> ulice = new List <UlicaView>(); try { ISession s = DataLayer.GetSession(); IEnumerable <Ulica> sveUlice = from a in s.Query <Ulica>() select a; foreach (Ulica a in sveUlice) { UlicaView tmp = new UlicaView(a); tmp.Policajac = new PozornikPolicajacView(a.Policajac); ulice.Add(tmp); } s.Close(); } catch (Exception e) { Console.WriteLine(e); throw; } return(ulice); }
public IActionResult IzmeniUlicu([FromBody] UlicaView c) { try { DataProvider.IzmeniUlicu(c); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.ToString())); } }
public IActionResult DodajUlicu([FromBody] UlicaView ul, int id) { try { var policajac = DataProvider.VratiPozornika(id); if (policajac == null) { return(BadRequest("Policajac null")); } ul.Policajac = policajac; DataProvider.DodajUlicu(ul); return(Ok()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public static void IzmeniUlicu(UlicaView c) { try { ISession s = DataLayer.GetSession(); var ulica = s.Get <Ulica>(c.UlicaId); ulica.Naziv = !string.IsNullOrEmpty(c.Naziv) ? c.Naziv : ulica.Naziv; s.SaveOrUpdate(ulica); s.Flush(); s.Close(); } catch (Exception e) { Console.WriteLine(e); throw; } }