Пример #1
0
        public IHttpActionResult VratiPogresnoSkinuteObroke([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.ModifikacijaObrok))
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)
                    {
                        Content = new StringContent("Nemate privilegiju")
                    });
                }


                Obrok o = ProvajderPodatakaObroka.VratiObrok(id);
                if (o != null && ProvajderPodatakaObroka.DanasSkinutiObrociKorisnika(o.Uplatilac.IdKorisnika).Contains(o))
                {
                    o.DatumIskoriscenja    = null;
                    o.Iskoriscen           = false;
                    o.LokacijaIskoriscenja = null;

                    ProvajderPodatakaObroka.UpdateObrok(o);
                }

                return(Ok("Korekcija uspesno obavljena."));
            }
            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();
            }
        }