public static void DodajCin(CinView c)
        {
            try
            {
                ISession s         = DataLayer.GetSession();
                var      cin       = new Cin();
                var      policajac = s.Get <Policajac>(c.Policajac.PolicajacId);
                if (policajac == null)
                {
                    return;
                }
                cin.Policajac     = policajac;
                cin.DatumSticanja = c.DatumSticanja;
                cin.Naziv         = c.Naziv;

                s.Save(cin);
                s.Flush();
                s.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        public static List <CinView> VratiCinovePolicajac(int id)
        {
            var cinovi = new List <CinView>();

            try
            {
                ISession          s         = DataLayer.GetSession();
                IEnumerable <Cin> svicinovi = from c in s.Query <Cin>()
                                              where c.Policajac.PolicajacId == id
                                              select c;

                foreach (var cin in svicinovi)
                {
                    var tmp = new CinView(cin);
                    tmp.Policajac = new PolicajacView(cin.Policajac);
                    cinovi.Add(tmp);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            return(cinovi);
        }
Exemplo n.º 3
0
 public IActionResult IzmeniCin([FromBody] CinView c)
 {
     try
     {
         DataProvider.IzmeniCin(c);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.ToString()));
     }
 }
Exemplo n.º 4
0
 public IActionResult DodajCin([FromBody] CinView cin, int id)
 {
     try
     {
         var policajac = DataProvider.VratiPolicajca(id);
         cin.Policajac = policajac;
         DataProvider.DodajCin(cin);
         return(Ok());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
        public static void IzmeniCin(CinView c)
        {
            try
            {
                ISession s   = DataLayer.GetSession();
                var      cin = s.Get <Cin>(c.CinId);

                cin.Naziv         = !string.IsNullOrEmpty(c.Naziv) ? c.Naziv : cin.Naziv;
                cin.DatumSticanja = c.DatumSticanja != DateTime.MinValue ? c.DatumSticanja : cin.DatumSticanja;

                s.SaveOrUpdate(cin);
                s.Flush();
                s.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }