public static ObjavaFullDto VratiObjavuDto(int id) { ISession s = SesijeProvajder.Sesija; Korisnik k = ProvajderPodatakaKorisnika.VratiKorisnika(id); if (k == null) { return(null); } if (k.TipNaloga.IdTip != 5) { return(null); } Objava o = k.Objava; ObjavaFullDto odto = new ObjavaFullDto() { IdObjave = o.IdObjave, IdKorisnika = o.IdKorisnik.IdKorisnika, IdLokacije = o.Lokacija.IdMenza, TekstObjave = o.TekstObjave, DatumObjave = o.DatumObjave.Value }; return(odto); }
public ObjavaFullDto PrikaziObjavu(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.PracenjeKorisnika)) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden) { Content = new StringContent("Nemate privilegiju") }); } ObjavaFullDto o = ProvajderPodatakaObjava.VratiObjavuDto(id); if (o == null) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("Objava ne postoji") }); } return(o); } 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(); } }