public static List <PatrolaView> VratiSvePatrole()
        {
            var patrole = new List <PatrolaView>();

            try
            {
                ISession s          = DataLayer.GetSession();
                var      svepatrole = from p in s.Query <Patrola>() select p;

                foreach (var patrola in svepatrole)
                {
                    var tmp = new PatrolaView(patrola);
                    tmp.Vodja        = new ObicanPolicajacView(patrola.Vodja);
                    tmp.Partner      = new ObicanPolicajacView(patrola.Partner);
                    tmp.Vozilo       = new SluzbenoVoziloView(patrola.Vozilo);
                    tmp.Intervencije = patrola.Intervencije.Select(i => new IntervencijaView(i)).ToList();
                    patrole.Add(tmp);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            return(patrole);
        }
        public static void DodajPatrolu(PatrolaView p)
        {
            try
            {
                ISession s       = DataLayer.GetSession();
                var      vodja   = s.Get <ObicanPolicajac>(p.Vodja.PolicajacId);
                var      partner = s.Get <ObicanPolicajac>(p.Partner.PolicajacId);
                var      vozilo  = s.Get <SluzbenoVozilo>(p.Vozilo.VoziloId);

                var patrola = new Patrola();

                patrola.Partner = partner;
                patrola.Vozilo  = vozilo;
                patrola.Vodja   = vodja;

                s.Save(patrola);
                s.Flush();
                s.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
示例#3
0
        public IActionResult DodajPatrolu([FromBody] PatrolaView patrola, int vodjaid, int partnerid, int voziloid)
        {
            try
            {
                var vodja   = DataProvider.VratiObicnogPolicajca(vodjaid);
                var partner = DataProvider.VratiObicnogPolicajca(partnerid);
                var vozilo  = DataProvider.VratiVozilo(voziloid);

                patrola.Vodja   = vodja;
                patrola.Partner = partner;
                patrola.Vozilo  = vozilo;
                DataProvider.DodajPatrolu(patrola);
                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
 public static PatrolaView VratiPatrolu(int id)
 {
     try
     {
         ISession s       = DataLayer.GetSession();
         var      p       = s.Get <Patrola>(id);
         var      patrola = new PatrolaView(p);
         patrola.Vozilo       = new SluzbenoVoziloView(p.Vozilo);
         patrola.Vodja        = new ObicanPolicajacView(p.Vodja);
         patrola.Partner      = new ObicanPolicajacView(p.Partner);
         patrola.Intervencije = p.Intervencije.Select(i => new IntervencijaView(i)).ToList();
         return(patrola);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }