Exemplo n.º 1
0
        public List <FakultetFullDto> VratiSveFakulteteFull([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.CitanjeFakultet))
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)
                    {
                        Content = new StringContent("Nemate privilegiju")
                    });
                }

                List <Fakultet>        listaFakulteta     = ProvajderPodatakaFakulteta.VratiFakultete();
                List <FakultetFullDto> listaFakultetaFull = new List <FakultetFullDto>(listaFakulteta.Count);


                if (listaFakulteta == null)
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                    {
                        Content = new StringContent("Fakulteti nisu pronadjeni")
                    });
                }

                foreach (Fakultet f in listaFakulteta)
                {
                    listaFakultetaFull.Add(new FakultetFullDto()
                    {
                        IdFakultet = f.IdFakultet,
                        Naziv      = f.Naziv
                    });
                }

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