Esempio n. 1
0
        public static bool AddMensa(Mensa m)
        {
            try
            {
                if (Mensa.Mensas.Exists(x => x.Name == m.Name))
                {
                    MUtility.ShowError("Menza sa tim nazivom vec postoji");
                    return(false);
                }

                MenzaFullDto mdto = new MenzaFullDto();
                mdto.Naziv          = m.Name;
                mdto.Lokacija       = m.Location;
                mdto.GpsLat         = m.GPSLat;
                mdto.GpsLong        = m.GPSLong;
                mdto.RadnoVreme     = m.WorkTime;
                mdto.VanrednoNeRadi = m.CurrentlyClosed;

                Api.AddNewMensa(mdto);
                Mensa.UpdateMensaList();
                return(true);
            }
            catch (Exception ex)
            {
                MUtility.ShowException(ex);
                return(false);
            }
        }
Esempio n. 2
0
        public IHttpActionResult UpdateMenzu([FromBody] MenzaFullDto mdto, [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.ModifikacijaMenza))
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)
                    {
                        Content = new StringContent("Nemate privilegiju")
                    });
                }

                Menza m = ProvajderPodatakaMenzi.VratiMenzu(mdto.IdMenze);

                if (m == null)
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                    {
                        Content = new StringContent("Menza za modifikaciju nije pronadjena")
                    });
                }

                m.Naziv          = mdto.Naziv;
                m.Lokacija       = mdto.Lokacija;
                m.RadnoVreme     = mdto.RadnoVreme;
                m.VanrednoNeRadi = mdto.VanrednoNeRadi;
                m.GpsLat         = mdto.GpsLat;
                m.GpsLon         = mdto.GpsLong;

                ProvajderPodatakaMenzi.UpdateMenzu(m);
                return(Ok("Menza uspesno modifikovana"));
            }
            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. 3
0
 public static Mensa Mensa_From_MenzaFullDto(MenzaFullDto mensa)
 {
     return(new Mensa()
     {
         MensaID = mensa.IdMenze,
         Name = mensa.Naziv,
         Location = mensa.Lokacija,
         CurrentlyClosed = mensa.VanrednoNeRadi,
         WorkTime = mensa.RadnoVreme
     });
 }
Esempio n. 4
0
        public IHttpActionResult DodajMenzu([FromBody] MenzaFullDto mdto, [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.DodavanjeMenza))
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)
                    {
                        Content = new StringContent("Nemate privilegiju")
                    });
                }

                ProvajderPodatakaMenzi.DodajMenzu(new Menza()
                {
                    Lokacija       = mdto.Lokacija,
                    Naziv          = mdto.Naziv,
                    RadnoVreme     = mdto.RadnoVreme,
                    VanrednoNeRadi = mdto.VanrednoNeRadi,
                    GpsLat         = mdto.GpsLat,
                    GpsLon         = mdto.GpsLong
                });

                return(Ok("Menza uspesno dodata"));
            }
            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 static void UpdateMenza(MenzaFullDto m)
        {
            RestRequest request = new RestRequest(Method.PUT);

            request.Resource = "menze/update";
            request.AddObject(m);

            var response = Execute(request);

            if (!(response.HttpStatusCode == HttpStatusCode.OK || response.HttpStatusCode == HttpStatusCode.Redirect))
            {
                throw new Exception("" + "\n" + response.ErrorResponse + "\nHttpStatus: " + response.HttpStatusCode);
            }
        }
Esempio n. 6
0
        public static void AddNewMensa(MenzaFullDto m)
        {
            RestRequest request = new RestRequest(Method.POST);

            request.Resource = "menze/dodaj";
            request.AddObject(m);

            var response = Execute(request);

            if (!(response.HttpStatusCode == HttpStatusCode.OK || response.HttpStatusCode == HttpStatusCode.Redirect))
            {
                throw new Exception("AddNewMensa Error" + "\nServerResponse: " + response.ErrorResponse + "\nHttpStatus: " + response.HttpStatusCode);
            }
        }
Esempio n. 7
0
        public static bool UpdateMensa(Mensa m)
        {
            try
            {
                MenzaFullDto mdto = new MenzaFullDto();
                mdto.IdMenze        = m.MensaID;
                mdto.GpsLat         = m.GPSLat;
                mdto.GpsLong        = m.GPSLong;
                mdto.Lokacija       = m.Location;
                mdto.RadnoVreme     = m.WorkTime;
                mdto.VanrednoNeRadi = m.CurrentlyClosed;
                mdto.Naziv          = m.Name;

                Api.UpdateMenza(mdto);
                Mensa.UpdateMensaList();
                return(true);
            }
            catch (Exception e)
            {
                MUtility.ShowException(e);
                return(false);
            }
        }
Esempio n. 8
0
        public MenzaFullDto VratiMenzuFull([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.CitanjeMenza))
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)
                    {
                        Content = new StringContent("Nemate privilegiju")
                    });
                }

                Menza        m     = null;
                MenzaFullDto menza = new MenzaFullDto();

                m = ProvajderPodatakaMenzi.VratiMenzu(id);
                if (m == null)
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                    {
                        Content = new StringContent("Menza nije pronadjena")
                    });
                }

                menza.IdMenze        = m.IdMenza;
                menza.Naziv          = m.Naziv;
                menza.Lokacija       = m.Lokacija;
                menza.RadnoVreme     = m.RadnoVreme;
                menza.VanrednoNeRadi = m.VanrednoNeRadi;
                menza.GpsLat         = m.GpsLat;
                menza.GpsLong        = m.GpsLon;

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