Exemple #1
0
        public IActionResult Rezervisi([FromBody] Klasa klasa) //id Smestaja
        {
            //prvo se proveri da li je u tabeli klijenti ako nije onda treba da se registruje
            //ako jeste onda da li slobodan smestaj
            //ako nije stavi datum u klijentu i smestajZaKoji je zainteresovan
            //ako jeste rezervisi
            TerminiProvider termin  = new TerminiProvider();
            KlijentProvider klijent = new KlijentProvider();

            if (klijent.Postoji(klasa.Klijent.Password, klasa.Klijent.Username))
            {
                if (termin.Slobodan(klasa.Termin, klasa.Soba, klasa.Klijent))
                {
                    var tip = new { tip = "Rezervisano" };
                    return(Ok(tip));
                }
                else
                {
                    var tip = new { tip = "Zauzet" };
                    return(Ok(tip));
                }
            }
            else
            {
                var tip = new { tip = "Nije ulogovan korisnik" };
                return(Ok(tip));
            }
        }
        public IActionResult Filter([FromBody] Filter filter)
        {
            SmestajProvider provider = new SmestajProvider();

            List <SmestajView> fsm = new List <SmestajView>();

            if (filter.C_min > 0 || filter.C_max > 0)
            {
                fsm = provider.FilterCena(filter.idDest, filter.C_min, filter.C_max);
            }

            if (filter.D_od != null || filter.D_do != null)
            {
                DateTime D_od = DateTime.Parse(filter.D_od);
                DateTime D_do = DateTime.Parse(filter.D_do);
                if (filter.D_od == null)
                {
                    D_od = new DateTime(2019, 1, 1);
                }
                if (filter.D_do == null)
                {
                    D_do = new DateTime(2119, 1, 1);
                }

                TerminiProvider tp = new TerminiProvider();

                List <SmestajView> sm   = provider.VratiS(filter.idDest);
                List <SmestajView> fsmD = new List <SmestajView>();
                foreach (SmestajView smes in sm)
                {
                    bool ima = tp.FilterDatum(smes.Id, D_od, D_do);
                    if (ima)
                    {
                        fsmD.Add(smes);
                    }
                }

                foreach (SmestajView smes in fsmD)
                {
                    if (!fsm.Contains(smes))
                    {
                        fsm.Add(smes);
                    }
                }
            }

            if (fsm == null)
            {
                return(NotFound());
            }
            var json = JsonConvert.SerializeObject(fsm, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            });

            return(Ok(json));
        }
        public IActionResult Post([FromBody] DataWrapper.AddTermini term)
        {
            TerminiProvider provider = new TerminiProvider();

            if (provider.AddTermini(term))
            {
                var tip = new { tip = "dodato" };
                return(Ok(tip));
            }
            return(NotFound());
        }
        public IActionResult Get()
        {
            TerminiProvider provider = new TerminiProvider();

            IEnumerable <Termini> term = provider.GetTermine();

            if (term == null)
            {
                return(NotFound());
            }
            var json = JsonConvert.SerializeObject(term);

            return(Ok(json));
        }
        public IActionResult VratiTermineZaSmestaj(int id)
        {
            TerminiProvider    provider = new TerminiProvider();
            List <TerminiView> t        = provider.VratiT_ZaS(id);

            if (t == null)
            {
                return(NotFound());
            }
            //var json = JsonConvert.SerializeObject(t);
            var json = JsonConvert.SerializeObject(t, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            });

            return(Ok(json));
        }
        public IActionResult Get(int id)
        {
            TerminiProvider provider = new TerminiProvider();
            Termini         t        = provider.GetTermini(id);

            if (t == null)
            {
                return(NotFound());
            }
            //var json = JsonConvert.SerializeObject(t);
            var json = JsonConvert.SerializeObject(t, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            });

            return(Ok(json));
        }
Exemple #7
0
        public IActionResult OtkaziRezervaciju([FromBody] Klasa klasa)
        {
            TerminiProvider termin  = new TerminiProvider();
            KlijentProvider klijent = new KlijentProvider();

            if (klijent.Postoji(klasa.Klijent.Password, klasa.Klijent.Username))
            {
                if (termin.Otkazi(klasa.Termin, klasa.Soba, klasa.Klijent))
                {
                    var tip = new { tip = "Otkazano" };
                    return(Ok(tip));
                }
                else
                {
                    var tip = new { tip = "Nije otkazana" };
                    return(Ok(tip));
                }
            }
            else
            {
                return(NotFound());
            }
        }
        public int Delete(int id)
        {
            TerminiProvider provider = new TerminiProvider();

            return(provider.RemoveTermini(id));
        }