コード例 #1
0
        public List <ObrokFullDto> VratiSveObroke([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.CitanjeObrok))
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)
                    {
                        Content = new StringContent("Nemate privilegiju")
                    });
                }


                List <Obrok>        listaObroka     = ProvajderPodatakaObroka.VratiObroke();
                List <ObrokFullDto> listaObrokaFull = new List <ObrokFullDto>(listaObroka.Count);

                if (listaObroka.Count == 0)
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                    {
                        Content = new StringContent("Obroci nisu pronadjeni")
                    });
                }


                foreach (Obrok o in listaObroka)
                {
                    ObrokFullDto obrok = new ObrokFullDto();

                    obrok.IdObroka         = o.IdObroka;
                    obrok.Iskoriscen       = o.Iskoriscen;
                    obrok.DatumUplacivanja = o.DatumUplacivanja;
                    if (o.DatumIskoriscenja != null)
                    {
                        obrok.DatumIskoriscenja = o.DatumIskoriscenja;
                    }
                    obrok.IdUplatioca      = o.Uplatilac.IdKorisnika;
                    obrok.IdTipaObroka     = o.Tip.IdTipObroka;
                    obrok.IdLokacijeUplate = o.LokacijaUplate.IdMenza;
                    if (o.LokacijaIskoriscenja != null)
                    {
                        obrok.IdLokacijeIskoriscenja = o.LokacijaIskoriscenja.IdMenza;
                    }

                    listaObrokaFull.Add(obrok);
                }
                return(listaObrokaFull);
            }
            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();
            }
        }
コード例 #2
0
        public ObrokFullDto VratiObrokFull([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.CitanjeObrok))
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)
                    {
                        Content = new StringContent("Nemate privilegiju")
                    });
                }

                Obrok        o     = null;
                ObrokFullDto obrok = new ObrokFullDto();

                o = ProvajderPodatakaObroka.VratiObrok(id);
                if (o == null)
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                    {
                        Content = new StringContent("Obrok nije pronadjen")
                    });
                }

                obrok.IdObroka         = o.IdObroka;
                obrok.Iskoriscen       = o.Iskoriscen;
                obrok.DatumUplacivanja = o.DatumUplacivanja;
                if (o.DatumIskoriscenja != null)
                {
                    obrok.DatumIskoriscenja = o.DatumIskoriscenja;
                }
                obrok.IdUplatioca      = o.Uplatilac.IdKorisnika;
                obrok.IdTipaObroka     = o.Tip.IdTipObroka;
                obrok.IdLokacijeUplate = o.LokacijaUplate.IdMenza;
                if (o.LokacijaIskoriscenja != null)
                {
                    obrok.IdLokacijeIskoriscenja = o.LokacijaIskoriscenja.IdMenza;
                }


                SesijeProvajder.ZatvoriSesiju();

                return(obrok);
            }
            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();
            }
        }