public static void UpdateMenzu(Menza m) { ISession s = SesijeProvajder.Sesija; s.Update(m); s.Flush(); }
public static void DodajMenzu(Menza m) { ISession s = SesijeProvajder.Sesija; s.Save(m); s.Flush(); }
public static Menza VratiMenzu(int id) { ISession s = SesijeProvajder.Sesija; Menza m = s.Get <Menza>(id); return(m); }
public IHttpActionResult UpdateMenzu([FromBody] MenzaFullDto mdto, [FromUri] string sid) { try { SesijeProvajder.OtvoriSesiju(); if (!ProvajderPodatakaKorisnika.SesijaValidna(sid)) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("Sesija istekla") }); } if (!ValidatorPrivilegija.KorisnikImaPrivilegiju(sid, ValidatorPrivilegija.UserPrivilegies.ModifikacijaMenza)) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden) { Content = new StringContent("Nemate privilegiju") }); } Menza m = ProvajderPodatakaMenzi.VratiMenzu(mdto.IdMenze); if (m == null) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("Menza za modifikaciju nije pronadjena") }); } m.Naziv = mdto.Naziv; m.Lokacija = mdto.Lokacija; m.RadnoVreme = mdto.RadnoVreme; m.VanrednoNeRadi = mdto.VanrednoNeRadi; m.GpsLat = mdto.GpsLat; m.GpsLon = mdto.GpsLong; ProvajderPodatakaMenzi.UpdateMenzu(m); return(Ok("Menza uspesno modifikovana")); } catch (Exception e) { if (e is HttpResponseException) { throw e; } DnevnikIzuzetaka.Zabelezi(e); throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent("InternalError: " + e.Message) }); } finally { SesijeProvajder.ZatvoriSesiju(); } }
public static void ObrisiMenzu(int id) { ISession s = SesijeProvajder.Sesija; Menza m = s.Load <Menza>(id); s.Delete(m); s.Flush(); }
public int GuzvaZaUplatu([FromUri] int id, [FromUri] string sid) { try { SesijeProvajder.OtvoriSesiju(); if (!ProvajderPodatakaKorisnika.SesijaValidna(sid)) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("Sesija istekla") }); } if (!ValidatorPrivilegija.KorisnikImaPrivilegiju(sid, ValidatorPrivilegija.UserPrivilegies.CitanjeGuzvaMenza)) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden) { Content = new StringContent("Nemate privilegiju") }); } Menza m = null; m = ProvajderPodatakaMenzi.VratiMenzu(id); if (m == null) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("Menza nije pronadjena") }); } int procenatGuzveZaUplatu = Convert.ToInt32(ProvajderPodatakaMenzi.BrojObrokaUplacenihUPoslednjihPetMinuta(id) * 0.1); if (procenatGuzveZaUplatu > 100) { procenatGuzveZaUplatu = 100; } return(procenatGuzveZaUplatu); } catch (Exception e) { if (e is HttpResponseException) { throw e; } DnevnikIzuzetaka.Zabelezi(e); throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent("InternalError: " + e.Message) }); } finally { SesijeProvajder.ZatvoriSesiju(); } }
public static List <Menza> VratiMenze() { ISession s = SesijeProvajder.Sesija; List <Menza> menze = s.Query <Menza>().Select(k => k).ToList(); Menza m = menze.First(x => x.IdMenza == 4); menze.Remove(m); return(menze.ToList()); }
public IHttpActionResult ObrisiMenzu([FromUri] int id, [FromUri] string sid) { try { SesijeProvajder.OtvoriSesiju(); if (!ProvajderPodatakaKorisnika.SesijaValidna(sid)) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("Sesija istekla") }); } if (!ValidatorPrivilegija.KorisnikImaPrivilegiju(sid, ValidatorPrivilegija.UserPrivilegies.BrisanjeMenza)) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden) { Content = new StringContent("Nemate privilegiju") }); } Menza m = null; m = ProvajderPodatakaMenzi.VratiMenzu(id); if (m == null) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("Menza za brisanje nije pronadjena") }); } ProvajderPodatakaMenzi.ObrisiMenzu(id); return(Ok("Menza uspesno obrisana")); } catch (Exception e) { if (e is HttpResponseException) { throw e; } DnevnikIzuzetaka.Zabelezi(e); throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent("InternalError: " + e.Message) }); } finally { SesijeProvajder.ZatvoriSesiju(); } }
public static ObjavaCUDto Objavi(int id, ObjavaCUDto ocudto) { ISession s = SesijeProvajder.Sesija; Korisnik ko = ProvajderPodatakaKorisnika.VratiKorisnika(id); if (ko == null) { return(null); } if (ko.TipNaloga.IdTip != 5) { return(null); } Objava o; if (ko.Objava != null) { o = ko.Objava; } else { o = NapraviObjavu(ko); } List <Menza> menze = s.Query <Menza>().Select(k => k).ToList(); Menza m = menze.Find(x => x.IdMenza == ocudto.IdLokacije); o.TekstObjave = ocudto.TekstObjave; o.Lokacija = m; o.DatumObjave = DateTime.Now; s.Save(o); s.Flush(); return(ocudto); }
public static bool MenzaPostoji(Menza m) { return(m != null); }
public MenzaFullDto VratiMenzuFull([FromUri] int id, [FromUri] string sid) { try { SesijeProvajder.OtvoriSesiju(); if (!ProvajderPodatakaKorisnika.SesijaValidna(sid)) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("Sesija istekla") }); } if (!ValidatorPrivilegija.KorisnikImaPrivilegiju(sid, ValidatorPrivilegija.UserPrivilegies.CitanjeMenza)) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden) { Content = new StringContent("Nemate privilegiju") }); } Menza m = null; MenzaFullDto menza = new MenzaFullDto(); m = ProvajderPodatakaMenzi.VratiMenzu(id); if (m == null) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("Menza nije pronadjena") }); } menza.IdMenze = m.IdMenza; menza.Naziv = m.Naziv; menza.Lokacija = m.Lokacija; menza.RadnoVreme = m.RadnoVreme; menza.VanrednoNeRadi = m.VanrednoNeRadi; menza.GpsLat = m.GpsLat; menza.GpsLong = m.GpsLon; return(menza); } catch (Exception e) { if (e is HttpResponseException) { throw e; } DnevnikIzuzetaka.Zabelezi(e); throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent("InternalError: " + e.Message) }); } finally { SesijeProvajder.ZatvoriSesiju(); } }