Exemplo n.º 1
0
        public List <MenzaFullDto> VratiSveMenze([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")
                    });
                }


                List <Menza>        listaMenzi     = ProvajderPodatakaMenzi.VratiMenze();
                List <MenzaFullDto> listaMenziFull = new List <MenzaFullDto>(listaMenzi.Count);

                if (listaMenzi.Count == 0)
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                    {
                        Content = new StringContent("Menze nisu pronadjene")
                    });
                }


                foreach (Menza m in listaMenzi)
                {
                    listaMenziFull.Add(new MenzaFullDto()
                    {
                        IdMenze        = m.IdMenza,
                        Naziv          = m.Naziv,
                        Lokacija       = m.Lokacija,
                        RadnoVreme     = m.RadnoVreme,
                        VanrednoNeRadi = m.VanrednoNeRadi,
                        GpsLat         = m.GpsLat,
                        GpsLong        = m.GpsLon
                    });
                }

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