Esempio n. 1
0
        public List <ObrokReklamacijaDto> DanasUplaceniObrociKorisnika([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")
                    });
                }


                List <Obrok> danasUplaceniObrociOvogKorisnika        = ProvajderPodatakaObroka.DanasUplaceniNeiskorisceniObrociKorisnika(id);
                List <ObrokReklamacijaDto> listaDanasUplacenihObroka = new List <ObrokReklamacijaDto>(danasUplaceniObrociOvogKorisnika.Count);

                foreach (Obrok o in danasUplaceniObrociOvogKorisnika)
                {
                    listaDanasUplacenihObroka.Add(new ObrokReklamacijaDto()
                    {
                        Datum        = o.DatumUplacivanja,
                        idMenza      = o.LokacijaUplate.IdMenza,
                        IdObroka     = o.IdObroka,
                        IdTipaObroka = o.Tip.IdTipObroka
                    });
                }

                return(listaDanasUplacenihObroka);
            }
            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();
            }
        }
Esempio n. 2
0
        public HttpResponseMessage SMSServis(FormDataCollection data)
        {
            string sms_text = data.Get("message");
            string secret   = data.Get("secret");

            if (secret != "secreta")
            {
                return(Request.CreateResponse(HttpStatusCode.OK, "Mensarium SMS Servis GRESKA: Neuspela autentfikacija!"));
            }

            string[] sadrzaj = sms_text.Split(' ');

            if (sadrzaj[0] != "MENSARIUM")
            {
                return(null);
            }

            int    id         = int.Parse(sadrzaj[1]);
            string tip        = sadrzaj[2];
            int    brojObroka = int.Parse(sadrzaj[3]);

            try
            {
                SesijeProvajder.OtvoriSesiju();

                bool status = ProvajderPodatakaObroka.UplatiObrok(id, brojObroka,
                                                                  ProvajderPodatakaObroka.SmsUplate[tip]);

                if (!status)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, "Greska: nevalidni parametri"));
                }

                Korisnik k = ProvajderPodatakaKorisnika.VratiKorisnika(id);

                KorisnikStanjeDto stanje = ProvajderPodatakaKorisnika.Stanje(k);

                string odgovor = string.Format("Uspešno ste uplatili {0} obroka tipa {1}. Stanje:  " +
                                               "Doručak:  {2}   Ručak:  {3}  Večera:  {4}",
                                               brojObroka,
                                               tip.ToLower(),
                                               stanje.BrojDorucka,
                                               stanje.BrojRuckova,
                                               stanje.BrojVecera);

                return(Request.CreateResponse(HttpStatusCode.OK, odgovor));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, "SMS SERVIS INTERNA GRESKA. POKUSAJTE KASNIJE"));
            }
            finally
            {
                SesijeProvajder.ZatvoriSesiju();
            }
        }
Esempio n. 3
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();
            }
        }
Esempio n. 4
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();
            }
        }
Esempio n. 5
0
        public IHttpActionResult NaplatiObroke([FromBody] ObrokNaplataDto obNapDto, [FromUri] string sid)
        {
            int i = 1;

            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")
                    });
                }

                while (i <= obNapDto.BrojObroka)
                {
                    Obrok obrokZaSkidanje = ProvajderPodatakaObroka.ObrokZaSkidanjeOvogTipa(obNapDto.IdKorisnika, obNapDto.IdTipa);
                    if (obrokZaSkidanje != null)
                    {
                        ProvajderPodatakaObroka.PojediObrok(obrokZaSkidanje.IdObroka, obNapDto.IdLokacijeIskoriscenja);
                        ++i;
                    }
                    else
                    {
                        break;
                    }
                }

                if (i == 1)
                {
                    return(Ok("Ne moze se skunuti, nema obroka"));
                }
                else
                {
                    return(Ok("Uspesno je skunuto " + (i - 1).ToString() + " obroka."));
                }
            }
            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();
            }
        }
Esempio n. 6
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();
            }
        }
Esempio n. 7
0
        public IHttpActionResult UplatiObroke([FromBody] ObrokUplataDto obUpDto, [FromUri] string sid)
        {
            int i;

            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.DodavanjeObrok))
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)
                    {
                        Content = new StringContent("Nemate privilegiju")
                    });
                }


                for (i = 0; i < obUpDto.BrojObroka; ++i)
                {
                    if (!ProvajderPodatakaObroka.KorisnikDostigaoLimitZaOvajMesecZaOvajObrok(obUpDto.IdKorisnika, obUpDto.IdTipa))
                    {
                        Obrok o = new Obrok
                        {
                            Iskoriscen        = false,
                            DatumUplacivanja  = DateTime.Now,
                            DatumIskoriscenja = null,
                            Uplatilac         = ProvajderPodatakaKorisnika.VratiKorisnika(obUpDto.IdKorisnika),
                            Tip                  = ProvajderPodatakaTipovaObroka.VratiTipObroka(obUpDto.IdTipa),
                            LokacijaUplate       = ProvajderPodatakaMenzi.VratiMenzu(obUpDto.IdLokacijeUplate),
                            LokacijaIskoriscenja = null
                        };

                        ProvajderPodatakaObroka.DodajObrok(o);
                    }
                    else
                    {
                        break;
                    }
                }
                if (i == 0)
                {
                    return(Ok("Ne moze se uopste uplatiti, dostignut je limit."));
                }
                else
                {
                    return(Ok("Uspesno je dodato " + i + " obroka."));
                }
            }
            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();
            }
        }