public List <Voznja> Get()
        {
            Korisnik user = (Korisnik)HttpContext.Current.Session["user"];

            if (user == null)
            {
                user = new Korisnik();
                HttpContext.Current.Session["user"] = user;
            }

            Vozaci vozaci = HttpContext.Current.Application["vozaci"] as Vozaci;

            if (user.Role == Uloga.Vozac)
            {
                foreach (Vozac v in vozaci.vozaci)
                {
                    if (user.KorisnickoIme == v.KorisnickoIme)
                    {
                        return(v.voznjeKorisnika);
                    }
                }
            }


            return(new List <Voznja>());
        }
        public bool Put(string id, [FromBody] Voznja v)
        {
            Korisnik user = (Korisnik)HttpContext.Current.Session["user"];

            if (user == null)
            {
                user = new Korisnik();
                HttpContext.Current.Session["user"] = user;
            }

            Vozaci vozaci = HttpContext.Current.Application["vozaci"] as Vozaci;
            Voznje voznje = HttpContext.Current.Application["voznje"] as Voznje;

            foreach (Vozac rider in vozaci.list)
            {
                if (rider.KorisnickoIme == user.KorisnickoIme && user.Uloga == Enums.Uloga.Vozac)
                {
                    if (v.StatusVoznje == Enums.StatusVoznje.Uspesna)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public bool Post([FromBody] Korisnik korisnik)
        {
            Korisnici users     = (Korisnici)HttpContext.Current.Application["korisnici"];
            Dispeceri dispeceri = (Dispeceri)HttpContext.Current.Application["dispeceri"];
            Vozaci    vozaci    = (Vozaci)HttpContext.Current.Application["vozaci"];

            foreach (var item in users.korisnici)
            {
                if (item.KorisnickoIme == korisnik.KorisnickoIme && item.Lozinka == korisnik.Lozinka)
                {
                    return(true);
                }
            }

            foreach (var item in dispeceri.dispecers)
            {
                if (item.KorisnickoIme == korisnik.KorisnickoIme && item.Lozinka == korisnik.Lozinka)
                {
                    return(true);
                }
            }

            foreach (var item in vozaci.vozaci)
            {
                if (item.KorisnickoIme == korisnik.KorisnickoIme && item.Lozinka == korisnik.Lozinka)
                {
                    return(true);
                }
            }
            return(false);
        }
        public string Post([FromBody] Korisnik korisnik) // Ispravnost user-a
        {
            Vozaci vozaci = (Vozaci)HttpContext.Current.Application["vozaci"];

            Korisnici korisnici = (Korisnici)HttpContext.Current.Application["korisnici"];
            Dispeceri dispeceri = (Dispeceri)HttpContext.Current.Application["dispeceri"];

            foreach (var k in korisnici.list)
            {
                if ((k.Value.Kime.Equals(korisnik.Kime)) && (k.Value.lozinka.Equals(korisnik.lozinka)))
                {
                    return("Uspesno");
                }
            }
            foreach (var k in dispeceri.list)
            {
                if ((k.Value.Kime.Equals(korisnik.Kime)) && (k.Value.lozinka.Equals(korisnik.lozinka)))
                {
                    return("Uspesno");
                }
            }
            foreach (var k in vozaci.list)
            {
                if ((k.Value.Kime.Equals(korisnik.Kime)) && (k.Value.lozinka.Equals(korisnik.lozinka)))
                {
                    return("Uspesno");
                }
            }
            return("Neuspesna prijava");
        }
        public Korisnik Get(string id)
        {
            Dispeceri dispeceri = (Dispeceri)HttpContext.Current.Application["dispeceri"];
            Korisnici users     = (Korisnici)HttpContext.Current.Application["korisnici"];
            Vozaci    vozaci    = (Vozaci)HttpContext.Current.Application["vozaci"];

            foreach (var item in users.korisnici)
            {
                if (id == item.KorisnickoIme)
                {
                    return(item);
                }
            }

            foreach (var item in dispeceri.dispecers)
            {
                if (id == item.KorisnickoIme)
                {
                    return(item);
                }
            }

            foreach (var item in vozaci.vozaci)
            {
                if (id == item.KorisnickoIme)
                {
                    return(item);
                }
            }

            return(null);
        }
Exemple #6
0
        public bool PutVozacNeuspesno(int id, [FromBody] Voznja voznja)        // Kad je voznja neuspesna
        {
            Voznje voznje = (Voznje)HttpContext.Current.Application["voznje"];
            Vozaci vozaci = (Vozaci)HttpContext.Current.Application["vozaci"];

            foreach (var item in voznje.voznje)
            {
                if (item.IdVoznje == id)
                {
                    item.Komentar.IdVoznje      = voznja.Komentar.IdVoznje;
                    item.Komentar.KorisnickoIme = voznja.Komentar.KorisnickoIme;
                    item.Komentar.OcenaVoznje   = voznja.Komentar.OcenaVoznje;
                    item.Komentar.Opis          = voznja.Komentar.Opis;
                    item.Komentar.DatumObjave   = item.Komentar.DatumObjave;
                    item.Status = voznja.Status;
                    item.Vozac  = voznja.Vozac;
                    item.Iznos  = voznja.Iznos;
                    foreach (var vozac in vozaci.vozaci)
                    {
                        if (vozac.KorisnickoIme == voznja.Vozac)
                        {
                            vozac.Zauzet = false;
                            IzmeniVozaca(vozac);
                            break;
                        }
                    }
                    UpisUTxt(item);
                    return(true);
                }
            }
            return(false);
        }
Exemple #7
0
        public List <Voznja> GetDriversRides()
        {
            Voznje voznje = HttpContext.Current.Application["voznje"] as Voznje;
            Vozaci vozaci = HttpContext.Current.Application["vozaci"] as Vozaci;

            Korisnik user = (Korisnik)HttpContext.Current.Session["user"];

            if (user == null)
            {
                user = new Korisnik();
                HttpContext.Current.Session["user"] = user;
            }

            if (user.KorisnickoIme != "" && user.KorisnickoIme != null && user.Role == Enums.Uloga.Vozac)
            {
                foreach (Vozac rider in vozaci.vozaci)
                {
                    if (rider.KorisnickoIme == user.KorisnickoIme)
                    {
                        return(rider.voznjeKorisnika);
                    }
                }
            }

            return(new List <Voznja>());
        }
Exemple #8
0
        public List <Voznja> GetUnclaimedRides()
        {
            Voznje voznje = HttpContext.Current.Application["voznje"] as Voznje;
            Vozaci vozaci = HttpContext.Current.Application["vozaci"] as Vozaci;

            List <Voznja> retVal = new List <Voznja>();

            Korisnik user = (Korisnik)HttpContext.Current.Session["user"];

            if (user == null)
            {
                user = new Korisnik();
                HttpContext.Current.Session["user"] = user;
            }

            if (user.KorisnickoIme != "" && user.KorisnickoIme != null && user.Role == Enums.Uloga.Vozac)
            {
                foreach (Voznja v in voznje.voznje)
                {
                    if (v.Status == Enums.Status.Kreirana_Na_Cekanju)
                    {
                        retVal.Add(v);
                    }
                }
                return(retVal);
            }

            return(new List <Voznja>());
        }
        private void LoadVozaci()
        {
            using (TextReader tr = new StreamReader(@"D:\TaxiService\WEBTaxiService\WEBTaxiService\TaxiService\App_Data\vozaci.txt"))
            {
                Vozac  vozac  = null;
                string podaci = "";
                while ((podaci = tr.ReadLine()) != null)
                {
                    string[] parsirani = podaci.Split(';');
                    vozac          = new Vozac();
                    vozac.Username = parsirani[0];
                    vozac.Password = parsirani[1];
                    vozac.Ime      = parsirani[2];
                    vozac.Prezime  = parsirani[3];
                    vozac.Pol      = (parsirani[4].Equals("Zenski") ? Pol.Zenski : Pol.Muski);
                    vozac.Jmbg     = parsirani[5];
                    vozac.Telefon  = parsirani[6];
                    vozac.Email    = parsirani[7];
                    vozac.Lokacija.Adresa.Ulica            = parsirani[8];
                    vozac.Lokacija.Adresa.Broj             = Int32.Parse(parsirani[9]);
                    vozac.Lokacija.Adresa.NaseljenoMesto   = parsirani[10];
                    vozac.Lokacija.Adresa.PozivniBrojMesta = Int32.Parse(parsirani[11]);
                    vozac.Automobil.Vozac    = parsirani[12];
                    vozac.Automobil.IdVozila = parsirani[13];
                    vozac.Automobil.BrojRegistarskeOznake = parsirani[14];
                    vozac.Automobil.GodisteAutomobila     = parsirani[15];
                    vozac.Automobil.TipAutomobila         = (Enums.TipAutomobila)System.Enum.Parse(typeof(Enums.TipAutomobila), parsirani[16]);


                    Vozaci.Add(vozac);
                }
            }
        }
Exemple #10
0
        public List <Voznja> GetVozacoveVoznje()
        {
            Voznje   voznje = HttpContext.Current.Application["voznje"] as Voznje;
            Vozaci   vozaci = HttpContext.Current.Application["vozaci"] as Vozaci;
            Korisnik user   = (Korisnik)HttpContext.Current.Session["user"];

            if (user == null)
            {
                user = new Korisnik();
                HttpContext.Current.Session["user"] = user;
            }

            if (user.KorisnickoIme != "" && user.KorisnickoIme != null && user.Uloga == Enums.Uloga.Vozac)
            {
                foreach (Vozac vozac in vozaci.list)
                {
                    if (vozac.KorisnickoIme == user.KorisnickoIme)
                    {
                        return(vozac.voznjeKorisnika);
                    }
                }
            }


            return(new List <Voznja>());
        }
        public List <Voznja> GetFiltracijaVozac(string id)
        {
            Vozaci   users = HttpContext.Current.Application["vozaci"] as Vozaci;
            Korisnik user  = (Korisnik)HttpContext.Current.Session["user"];

            if (user == null)
            {
                user = new Korisnik();
                HttpContext.Current.Session["user"] = user;
            }

            List <Voznja> search = HttpContext.Current.Session["search"] as List <Voznja>;

            if (search == null)
            {
                search = new List <Voznja>();
                HttpContext.Current.Session["search"] = search;
            }

            List <Voznja> retVal = new List <Voznja>();


            foreach (Voznja v in user.voznjeKorisnika)
            {
                if (v.StatusVoznje.ToString() == id)
                {
                    retVal.Add(v);
                }
            }

            HttpContext.Current.Session["search"] = retVal;

            return(retVal);
        }
 public ActionResult DeleteConfirmed(int id)
 {
     Vozaci vozaci = db.Vozaci.Find(id);
     db.Vozaci.Remove(vozaci);
     db.SaveChanges();
     return RedirectToAction("Index");
 }
Exemple #13
0
        public List <Voznja> GetSlobodne()
        {
            Voznje voznje = HttpContext.Current.Application["voznje"] as Voznje;
            Vozaci vozaci = HttpContext.Current.Application["vozaci"] as Vozaci;

            List <Voznja> retVal = new List <Voznja>();

            Korisnik user = (Korisnik)HttpContext.Current.Session["user"];

            if (user == null)
            {
                user = new Korisnik();
                HttpContext.Current.Session["user"] = user;
            }

            if (user.KorisnickoIme != "" && user.KorisnickoIme != null && user.Uloga == Enums.Uloga.Vozac)
            {
                foreach (Voznja v in voznje.list)
                {
                    if (v.StatusVoznje == Enums.StatusVoznje.Kreirana)
                    {
                        retVal.Add(v);
                    }
                }
                return(retVal);
            }

            return(new List <Voznja>());
        }
Exemple #14
0
        public bool GetStatus(int id)
        {
            Korisnik user = (Korisnik)HttpContext.Current.Session["user"];

            if (user == null)
            {
                user = new Korisnik();
                HttpContext.Current.Session["user"] = user;
            }


            Vozaci vozaci = HttpContext.Current.Application["vozaci"] as Vozaci;
            Voznje voznje = HttpContext.Current.Application["voznje"] as Voznje;

            foreach (Vozac driver in vozaci.vozaci)
            {
                if (driver.KorisnickoIme == user.KorisnickoIme)
                {
                    foreach (Voznja v in driver.voznjeKorisnika)
                    {
                        if (v.IdVoznje == id)
                        {
                            if (v.Status == Enums.Status.Uspesna || v.Status == Enums.Status.Neuspesna)
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            return(true);
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            Korisnici korisnici = new Korisnici("~/Baza/korisnici.txt");

            HttpContext.Current.Application["korisnici"] = korisnici;

            Dispeceri dispeceri = new Dispeceri("~/Baza/dispeceri.txt");

            HttpContext.Current.Application["dispeceri"] = dispeceri;

            Vozaci vozaci = new Vozaci("~/Baza/vozaci.txt");

            HttpContext.Current.Application["vozaci"] = vozaci;

            Voznje voznje = new Voznje("~/Baza/voznje.txt");

            HttpContext.Current.Application["voznje"] = voznje;
            Komentari komentari = new Komentari("~/Baza/komentari.txt");

            HttpContext.Current.Application["komentari"] = komentari;
        }
Exemple #16
0
        public bool PutVozac(int id, [FromBody] Voznja voznja)        // Dodavanje vozaca za voznju
        {
            Voznje voznje = (Voznje)HttpContext.Current.Application["voznje"];
            Vozaci vozaci = (Vozaci)HttpContext.Current.Application["vozaci"];

            foreach (var item in voznje.voznje)
            {
                if (item.IdVoznje == id)
                {
                    foreach (var vozac in vozaci.vozaci)
                    {
                        if (vozac.KorisnickoIme == voznja.Vozac)
                        {
                            vozac.Zauzet = true;
                            IzmeniVozaca(vozac);
                            break;
                        }
                    }
                    item.Vozac    = voznja.Vozac;
                    item.Iznos    = voznja.Iznos;
                    item.Dispecer = voznja.Dispecer;
                    item.Status   = voznja.Status;
                    UpisUTxt(item);
                    return(true);
                }
            }
            return(false);
        }
        public bool Put(string id, [FromBody] Vozac vozac)                     //menjam samo vozaca
        {
            Vozaci vozaci = (Vozaci)HttpContext.Current.Application["vozaci"]; //sve voznje


            Vozac vv = vozaci.list[id];

            /*   if (vozac.Ban != 2)
             * {
             *     vv.Ban = vozac.Ban;
             * }*/

            if (vozac.Zauzet != 2)
            {
                vv.Zauzet = vozac.Zauzet;
            }

            string path = "~/Baza/vozaci.txt";

            path = HostingEnvironment.MapPath(path);

            var lines = File.ReadAllLines(path);

            lines[int.Parse(id)] = vv.Id + ";" + vv.Kime + ";" + vv.lozinka + ";" + vv.ime + ";" + vv.prezime + ";" + vv.JMBG + ";" + vv.telefon + ";" + vv.pol + ";" + vv.email + ";" + vv.Lokacija.x + ";" + vv.Lokacija.y + ";" + vv.Lokacija.adresa.UlicaBroj + ";" + vv.Lokacija.adresa.NaseljenoMesto + ";" + vv.Lokacija.adresa.PozivniBrojMesta + ";" + vv.Automobil.BrTaksija + ";" + vv.Automobil.godiste + ";" + vv.Automobil.BrRegistracije + ";" + vv.Automobil.tipAuta + ";" + vv.Zauzet;
            File.WriteAllLines(path, lines);

            vozaci = new Vozaci("~/Baza/vozaci.txt");
            HttpContext.Current.Application["vozaci"] = vozaci;
            return(true);
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            Dispeceri dispeceri = new Dispeceri("~/App_Data/Dispeceri.txt");

            HttpContext.Current.Application["dispeceri"] = dispeceri as Dispeceri;

            Korisnici korisnici = new Korisnici("~/App_Data/Korisnici.txt");

            HttpContext.Current.Application["korisnici"] = korisnici as Korisnici;

            Vozaci vozaci = new Vozaci("~/App_Data/Vozaci.txt");

            HttpContext.Current.Application["vozaci"] = vozaci as Vozaci;

            Voznje voznje = new Voznje("~/App_Data/Voznje.txt");

            HttpContext.Current.Application["voznje"] = voznje;

            Korisnik user = new Korisnik();

            HttpContext.Current.Application["user"] = user as Korisnik;
        }
Exemple #19
0
        public bool PutVozacUspesno(int id, [FromBody] Voznja voznja)        // Postavljanje voznje kao uspesno
        {
            Voznje voznje = (Voznje)HttpContext.Current.Application["voznje"];
            Vozaci vozaci = (Vozaci)HttpContext.Current.Application["vozaci"];

            foreach (var item in voznje.voznje)
            {
                if (item.IdVoznje == id)
                {
                    item.Odrediste.X = voznja.Odrediste.X;
                    item.Odrediste.Y = voznja.Odrediste.Y;
                    item.Odrediste.Adresa.UlicaBroj = voznja.Odrediste.Adresa.UlicaBroj;

                    string[] dijelovi = voznja.Odrediste.Adresa.NaseljenoMjesto.Split(' ');
                    voznja.Odrediste.Adresa.NaseljenoMjesto = null;
                    dijelovi = dijelovi.Where(x => !string.IsNullOrEmpty(x)).ToArray();

                    int br = 0;
                    for (int i = 0; i < dijelovi.Length; i++)
                    {
                        int  n;
                        bool isNumeric = Int32.TryParse(dijelovi[i], out n);
                        if (isNumeric)
                        {
                            voznja.Odrediste.Adresa.PozivniBroj = dijelovi[i];
                            break;
                        }
                        else
                        {
                            if (br > 0)
                            {
                                voznja.Odrediste.Adresa.NaseljenoMjesto += " " + dijelovi[i];
                            }
                            else
                            {
                                voznja.Odrediste.Adresa.NaseljenoMjesto += dijelovi[i];
                                br++;
                            }
                        }
                    }

                    item.Odrediste.Adresa.NaseljenoMjesto = voznja.Odrediste.Adresa.NaseljenoMjesto;
                    item.Odrediste.Adresa.PozivniBroj     = voznja.Odrediste.Adresa.PozivniBroj;
                    item.Status = voznja.Status;
                    item.Iznos  = voznja.Iznos;
                    UpisUTxt(item);
                    foreach (var vozac in vozaci.vozaci)
                    {
                        if (vozac.KorisnickoIme == voznja.Vozac)
                        {
                            vozac.Zauzet = false;
                            IzmeniVozaca(vozac);
                            break;
                        }
                    }
                    return(true);
                }
            }
            return(false);
        }
Exemple #20
0
        public void UcitajVozace()
        {
            using (TextReader tr = new StreamReader(@"C:\Users\Nemanja\Desktop\FAKS\3.GODINA\WEB\TaxiSluzbaWebApp\TaxiService\TaxiSluzbaWebApi\App_Data\Vozaci.txt"))
            {
                Vozac  vozac       = null;
                string informacije = string.Empty;
                while ((informacije = tr.ReadLine()) != null)
                {
                    string[] parametri = informacije.Split(';');
                    vozac = new Vozac()
                    {
                        KorisnickoIme  = parametri[0],
                        Sifra          = parametri[1],
                        Ime            = parametri[2],
                        Prezime        = parametri[3],
                        Pol            = (parametri[4].Equals("Muski")) ? Enum.Pol.Muski : Enum.Pol.Zenski,
                        JMBG           = parametri[5],
                        KontaktTelefon = parametri[6],
                        Email          = parametri[7],
                        Blokiran       = (parametri[12].Equals("False")) ? false : true,
                        Automobil      = new Automobil()
                    };

                    vozac.Automobil.BrojRegistarskeOznake = parametri[8];
                    vozac.Automobil.Godiste         = parametri[9];
                    vozac.Automobil.BrojTaksiVozila = parametri[10];
                    vozac.Automobil.TipAutomobila   = (Enum.TipAutomobila)System.Enum.Parse(typeof(Enum.TipAutomobila), parametri[11]);
                    Vozaci.Add(vozac);
                }
            }
        }
        public Korisnik Post([FromBody] Korisnik korisnik)
        {
            Dispeceri dispeceri = (Dispeceri)HttpContext.Current.Application["dispeceri"];
            Korisnici users     = (Korisnici)HttpContext.Current.Application["korisnici"];
            Vozaci    vozaci    = (Vozaci)HttpContext.Current.Application["vozaci"];

            foreach (var item in users.korisnici)
            {
                if (korisnik.KorisnickoIme == item.KorisnickoIme)
                {
                    return(item);
                }
            }

            foreach (var item in dispeceri.dispecers)
            {
                if (korisnik.KorisnickoIme == item.KorisnickoIme)
                {
                    return(item);
                }
            }

            foreach (var item in vozaci.vozaci)
            {
                if (korisnik.KorisnickoIme == item.KorisnickoIme)
                {
                    return(item);
                }
            }

            return(null);
        }
Exemple #22
0
        public Korisnik Get(string id)  //Prijava
        {
            Korisnik  k         = null; //Ovo je samo po sebi validacija
            Korisnici korisnici = (Korisnici)HttpContext.Current.Application["korisnici"];
            Dispeceri dispeceri = (Dispeceri)HttpContext.Current.Application["dispeceri"];
            Vozaci    vozaci    = (Vozaci)HttpContext.Current.Application["vozaci"];

            //Validacija

            if (korisnici.list == null)
            {
                korisnici.list = new Dictionary <string, Korisnik>();
            }

            if (dispeceri.list == null)
            {
                dispeceri.list = new Dictionary <string, Dispecer>();
            }

            if (vozaci.list == null)
            {
                vozaci.list = new Dictionary <string, Vozac>();
            }


            foreach (var kk in korisnici.list)
            {
                if (kk.Value.KorisnickoIme == id)
                {
                    k       = kk.Value;
                    k.Uloga = Models.Enums.Enumss.Uloga.Musterija;
                    return(k);
                }
            }

            foreach (var kk in dispeceri.list)
            {
                if (kk.Value.KorisnickoIme == id)
                {
                    k       = kk.Value;
                    k.Uloga = Models.Enums.Enumss.Uloga.Dispecer;

                    return(k);
                }
            }

            foreach (var kk in vozaci.list)
            {
                if (kk.Value.KorisnickoIme == id)
                {
                    k       = kk.Value;
                    k.Uloga = Models.Enums.Enumss.Uloga.Vozac;

                    return(k);
                }
            }

            return(k);
        }
        public List<Voznja> GetSearchVozac(DateTime from, DateTime to)
        {
            Vozaci users = HttpContext.Current.Application["vozaci"] as Vozaci;
            Korisnik user = (Korisnik)HttpContext.Current.Session["user"];
            if (user == null)
            {
                user = new Korisnik();
                HttpContext.Current.Session["user"] = user;
            }


            List<Voznja> search = HttpContext.Current.Session["search"] as List<Voznja>;

            if (search == null)
            {
                search = new List<Voznja>();
                HttpContext.Current.Session["search"] = search;
            }


            List<Voznja> retVal = new List<Voznja>();
            int result1;
            int result2;

            /*foreach (Vozac k in users.vozaci)
            {
                if (k.KorisnickoIme == user.KorisnickoIme)
                {
                    foreach (Voznja v in k.voznjeKorisnika)
                    {
                        result1 = DateTime.Compare(from, v.VremePorudzbine);
                        result2 = DateTime.Compare(to, v.VremePorudzbine);

                        if (result1 < 0 && result2 > 0)
                        {
                            retVal.Add(v);
                        }
                    }

                    return retVal;
                }
            }*/


            foreach (Voznja v in search)
            {
                result1 = DateTime.Compare(from, v.VremePorudzbine);
                result2 = DateTime.Compare(to, v.VremePorudzbine);

                if (result1 < 0 && result2 > 0)
                {
                    retVal.Add(v);
                }
            }

            HttpContext.Current.Session["search"] = retVal;

            return retVal;
        }
        public bool PostVozac([FromBody] Vozac v)
        {
            Vozaci   vozaci = HttpContext.Current.Application["vozaci"] as Vozaci;
            Korisnik user   = HttpContext.Current.Session["user"] as Korisnik;

            if (user == null)
            {
                user = new Korisnik();
                HttpContext.Current.Session["user"] = user;
            }

            if (user.Role == Uloga.Dispecer)
            {
                foreach (Vozac vozac in vozaci.vozaci)
                {
                    if (v.KorisnickoIme == vozac.KorisnickoIme)
                    {
                        return(false);
                    }
                }

                v.Id              = vozaci.vozaci.Count;
                v.Role            = Uloga.Vozac;
                v.Automobil.Vozac = v.KorisnickoIme;
                v.stanjeVozaca    = Stanje.Slobodan;

                vozaci.vozaci.Add(v);

                //string path = @"C:\Users\Coa\Desktop\NovaVerzija\WebAPI\WebAPI\App_Data\vozaci.txt";
                string path = "~/App_Data/vozaci.txt";
                path = HostingEnvironment.MapPath(path);

                string line = String.Empty;
                line = v.Id.ToString() + '|' + v.KorisnickoIme + '|' + v.Lozinka + '|' + v.Ime + '|' +
                       v.Prezime + '|' + v.Gender + '|' + v.JMBG + '|' + v.Telefon + '|' + v.Email + '|' + v.Role +
                       '|' + v.Lokacija.X + '|' + v.Lokacija.Y + '|' + v.Lokacija.Adresa.UlicaBroj + '|' + v.Lokacija.Adresa.NaseljenoMesto +
                       '|' + v.Lokacija.Adresa.PozivniBroj + '|' + v.Automobil.Vozac + '|' + v.Automobil.GodisteAutomobila + '|' + v.Automobil.BrojRegistarskeOznake +
                       '|' + v.Automobil.BrojTaksiVozila + '|' + v.Automobil.Tip + '|' + v.stanjeVozaca + '|' + v.Nalog + Environment.NewLine;

                if (!File.Exists(path))
                {
                    File.WriteAllText(path, line);
                }
                else
                {
                    File.AppendAllText(path, line);
                }

                Vozaci vozaci2 = new Vozaci(@"~/App_Data/vozaci.txt");
                HttpContext.Current.Application["vozaci"] = vozaci2;

                return(true);
            }
            else
            {
                return(false);
            }
        }
        public bool PutVoznjaNeuspesno(int id, [FromBody] Komentar k)
        {
            Korisnik user = (Korisnik)HttpContext.Current.Session["user"];

            if (user == null)
            {
                user = new Korisnik();
                HttpContext.Current.Session["user"] = user;
            }

            Vozaci vozaci = HttpContext.Current.Application["vozaci"] as Vozaci;
            Voznje voznje = HttpContext.Current.Application["voznje"] as Voznje;

            foreach (Vozac driver in vozaci.list)
            {
                if (user.KorisnickoIme == driver.KorisnickoIme)
                {
                    foreach (Voznja ride in driver.voznjeKorisnika)
                    {
                        if (ride.Id == id)
                        {
                            ride.StatusVoznje         = Enums.StatusVoznje.Neuspesna;
                            ride.Komentar.Id          = id;
                            ride.Komentar.DatumObjave = DateTime.UtcNow.ToString();
                            ride.Komentar.idKorisnik  = user.KorisnickoIme;
                            ride.Komentar.Ocena       = k.Ocena;
                            ride.Komentar.Opis        = k.Opis;

                            //string path = @"C:\Users\Coa\Desktop\NovaVerzija\WebAPI\WebAPI\App_Data\voznje.txt";
                            string path = "~/App_Data/Voznje.txt";
                            path = HostingEnvironment.MapPath(path);

                            string line = String.Empty;
                            line = ride.Id.ToString() + '|' + ride.DatumVreme.ToString() + '|' + ride.Lokacija.X + '|' + ride.Lokacija.Y + '|' +
                                   ride.Lokacija.Adresa.UlicaBroj + '|' + ride.Lokacija.Adresa.NaseljenoMesto + '|' + ride.Lokacija.Adresa.PozivniBrojMesta + '|' + ride.Automobil + '|' +
                                   ride.idKorisnik + '|' + ride.Odrediste.X + '|' + ride.Odrediste.Y + '|' + ride.Odrediste.Adresa.UlicaBroj + '|' + ride.Odrediste.Adresa.NaseljenoMesto + '|' + ride.Odrediste.Adresa.PozivniBrojMesta + '|' +
                                   ride.idDispecer + '|' + ride.idVozac + '|' + ride.Iznos + '|' + ride.Komentar.Opis + '|' + ride.Komentar.DatumObjave + '|' + ride.Komentar.idKorisnik + '|' + ride.Komentar.idVoznja + '|' +
                                   ride.Komentar.Ocena + '|' + ride.StatusVoznje;


                            string[] arrLine2 = File.ReadAllLines(path);
                            arrLine2[ride.Id] = line;
                            File.WriteAllLines(path, arrLine2);


                            Voznje voznje2 = new Voznje("~/App_Data/Voznje.txt");
                            HttpContext.Current.Application["voznje"] = voznje2;
                            Vozaci vozaci2 = new Vozaci(@"~/App_Data/Vozaci.txt");
                            HttpContext.Current.Application["vozaci"] = vozaci2;

                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
 public ActionResult Delete(int id = 0)
 {
     Vozaci vozaci = db.Vozaci.Find(id);
     if (vozaci == null)
     {
         return HttpNotFound();
     }
     return View(vozaci);
 }
        public List <Voznja> GetSearchPriceVozac(double from, double to)
        {
            Vozaci   users = HttpContext.Current.Application["vozaci"] as Vozaci;
            Korisnik user  = (Korisnik)HttpContext.Current.Session["user"];

            if (user == null)
            {
                user = new Korisnik();
                HttpContext.Current.Session["user"] = user;
            }

            List <Voznja> search = HttpContext.Current.Session["search"] as List <Voznja>;

            if (search == null)
            {
                search = new List <Voznja>();
                HttpContext.Current.Session["search"] = search;
            }

            bool flag1 = true;
            bool flag2 = true;

            if (from == -1)
            {
                flag1 = false;
            }

            if (to == -1)
            {
                flag2 = false;
            }

            List <Voznja> retVal = new List <Voznja>();


            foreach (Voznja v in search)
            {
                if (!flag1)
                {
                    from = v.Iznos;
                }

                if (!flag2)
                {
                    to = v.Iznos;
                }

                if (v.Iznos >= from && v.Iznos <= to)
                {
                    retVal.Add(v);
                }
            }

            HttpContext.Current.Session["search"] = retVal;

            return(retVal);
        }
Exemple #28
0
        public bool Put([FromBody] Vozac vozac)         // Vozac mjenja svoju trenutnu lokaciju
        {
            Vozaci vozaci = (Vozaci)HttpContext.Current.Application["vozaci"];
            string path   = "~/App_Data/Vozaci.txt";

            path = HostingEnvironment.MapPath(path);
            foreach (var item in vozaci.vozaci)
            {
                if (item.Id == vozac.Id)
                {
                    item.Lokacija.X = vozac.Lokacija.X;
                    item.Lokacija.Y = vozac.Lokacija.Y;
                    item.Lokacija.Adresa.UlicaBroj = vozac.Lokacija.Adresa.UlicaBroj;

                    string[] dijelovi = vozac.Lokacija.Adresa.NaseljenoMjesto.Split(' ');
                    vozac.Lokacija.Adresa.NaseljenoMjesto = null;
                    dijelovi = dijelovi.Where(x => !string.IsNullOrEmpty(x)).ToArray();

                    int br = 0;
                    for (int i = 0; i < dijelovi.Length; i++)
                    {
                        int  n;
                        bool isNumeric = Int32.TryParse(dijelovi[i], out n);
                        if (isNumeric)
                        {
                            vozac.Lokacija.Adresa.PozivniBroj = dijelovi[i];
                            break;
                        }
                        else
                        {
                            if (br > 0)
                            {
                                vozac.Lokacija.Adresa.NaseljenoMjesto += " " + dijelovi[i];
                            }
                            else
                            {
                                vozac.Lokacija.Adresa.NaseljenoMjesto += dijelovi[i];
                                br++;
                            }
                        }
                    }

                    item.Lokacija.Adresa.NaseljenoMjesto = vozac.Lokacija.Adresa.NaseljenoMjesto;
                    item.Lokacija.Adresa.PozivniBroj     = vozac.Lokacija.Adresa.PozivniBroj;
                    StringBuilder sb = new StringBuilder();
                    sb.Append(item.Id + ";" + item.KorisnickoIme + ";" + item.Lozinka + ";" + item.Ime + ";" + item.Prezime + ";" + item.Pol + ";" + item.JMBG + ";" + item.Telefon + ";" + item.Email + ";" + item.Uloga + ";" + item.Voznja + ";" + item.Lokacija.X + ";" + item.Lokacija.Y + ";" + item.Lokacija.Adresa.UlicaBroj + ";" + item.Lokacija.Adresa.NaseljenoMjesto + ";" + item.Lokacija.Adresa.PozivniBroj + ";" + item.Automobil.Vozac + ";" + item.Automobil.GodisteAutomobila + ";" + item.Automobil.BrojRegistarskeOznake + ";" + item.Automobil.BrojTaksiVozila + ";" + item.Automobil.Tip + ";" + item.Zauzet + "\n");
                    string[] arrLine = File.ReadAllLines(path);
                    arrLine[item.Id - 1] = sb.ToString();
                    File.WriteAllLines(path, arrLine);
                    File.WriteAllLines(path, File.ReadAllLines(path).Where(l => !string.IsNullOrWhiteSpace(l)));
                    vozaci = new Vozaci("~/App_Data/Vozaci.txt");
                    HttpContext.Current.Application["vozaci"] = vozaci;
                    return(true);
                }
            }
            return(false);
        }
        public Lokacija Get(int id)
        {
            Lokacija lokacija = new Lokacija();
            Vozaci   vozaci   = (Vozaci)HttpContext.Current.Application["vozaci"];

            lokacija = vozaci.list[id.ToString()].Lokacija;


            return(lokacija);
        }
        public ActionResult Edit(Vozaci vozaci)
        {

            String username = "";
            if (Request["KorisnickoIme"] != null)
                username = Request["KorisnickoIme"].ToString();

            Korisnik k = db.Korisnik.Where(c => c.KorisnickoIme.Equals(username)).SingleOrDefault();

            if (k == null && !username.Equals(""))
                ModelState.AddModelError("KorisnickoIme", "Ne postoji unešeno korisničko ime");


            if (ModelState.IsValid)
            {

                if (Request["_ZapisAktivan"] != null)
                {
                    if (Request["_ZapisAktivan"].ToString().Equals("on"))
                        vozaci.ZapisAktivan = true;
                    else
                        vozaci.ZapisAktivan = false;
                }
                else vozaci.ZapisAktivan = false;

                db.Entry(vozaci).State = EntityState.Modified;

                if (!username.Equals(""))
                {

                    VozacUser vu = db.VozacUser.Where(c => c.IdVozac == vozaci.IdVozac).SingleOrDefault();
                    if (vu == null)
                    {
                        vu = new VozacUser();
                        vu.IdUser = k.IdKorisnik;
                        vu.IdVozac = vozaci.IdVozac;

                        db.VozacUser.Add(vu);
                    }
                    else
                    {
                        vu.IdUser = k.IdKorisnik;
                        db.Entry(vu).State = EntityState.Modified;
                    }

                   
                }

                db.SaveChanges();
                return RedirectToAction("Index");
            }
            var subjekti = db.Subjekt.Where(c => c.ZapisAktivan);
            ViewBag.IdSubjekt = new SelectList(subjekti, "IdSubjekt", "Naziv", vozaci.IdSubjekt);
            return View(vozaci);
        }