示例#1
0
        public IActionResult NovaKancelarija(Kancelarija input)
        {
            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    var kancelarija = new Kancelarija {
                        Ime = input.Ime
                    };

                    if (input != null)
                    {
                        _context.Kancelarijas.Add(kancelarija);
                        _context.SaveChanges();
                        transaction.Commit();


                        return(Ok());
                    }
                }

                catch (Exception e)
                {
                    return(BadRequest());
                }

                return(BadRequest());
            }
        }
示例#2
0
        public IActionResult NoviUredjaj(UredjajDto input)
        {
            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    if (input != null)
                    {
                        var uredjaj = new Uredjaj {
                            Ime = input.Ime, Id = input.Id
                        };
                        _context.Uredjajs.Add(uredjaj);
                        _context.SaveChanges();
                        transaction.Commit();

                        return(Ok());
                    }
                }

                catch (Exception e)
                {
                    return(BadRequest());
                }
            }

            return(BadRequest());
        }
        public IActionResult OsobaUredjajResult(string ime, string prezime, string uredjaj)
        {
            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    var istorija = new OsobaUredjaj
                    {
                        VrijemeOd = DateTime.Now,
                    };

                    var osobe      = _context.Osobas;
                    var osobeQuery =
                        osobe.Where(x => x.Ime.Equals(ime) && x.Prezime.Equals(prezime)).Select(osoba => osoba.Id).FirstOrDefault();

                    var uredjaji      = _context.Uredjajs;
                    var uredjajiQuery =
                        uredjaji.Where(x => x.Ime.Equals(uredjaj)).Select(d => d.Id).FirstOrDefault();


                    var korUredjaji      = _context.OsobaUredjajs;
                    var korUredjajiQuery =
                        korUredjaji.Where(x => x.UredjajId == uredjajiQuery && x.VrijemeDo == null).Select(y => y.Id);

                    var izmjena = _context.OsobaUredjajs.Find(korUredjajiQuery.FirstOrDefault());

                    if (korUredjajiQuery.Count() != 0)
                    {
                        izmjena.VrijemeDo = DateTime.Now;
                        _context.SaveChanges();
                    }
                    if (osobeQuery != null && uredjajiQuery != null)
                    {
                        istorija.OsobaId   = osobeQuery;
                        istorija.UredjajId = uredjajiQuery;
                    }
                    else
                    {
                        return(BadRequest());
                    }
                    _context.OsobaUredjajs.Add(istorija);
                    _context.SaveChanges();
                    transaction.Commit();
                    return(Ok(korUredjajiQuery.ToString()));
                }
                catch (Exception e)
                {
                    return(BadRequest());
                }
            }
        }
示例#4
0
        public IActionResult NovaOsoba(OsobaDto input)
        {
            using (var transaction = _context.Database.BeginTransaction())

            {
                try
                {
                    if (input != null)
                    {
                        var osoba = new Osoba
                        {
                            Ime           = input.Ime,
                            Prezime       = input.Prezime,
                            KancelarijaId = input.KancelarijaId
                        };

                        _context.Osobas.Add(osoba);
                        _context.SaveChanges();

                        var novaOsoba            = _context.Osobas.Last();
                        var novaOsobaKancelarija = novaOsoba.KancelarijaId;

                        var kancelarijaIme = _context.Kancelarijas.Where(k => k.Id == novaOsobaKancelarija)
                                             .FirstOrDefault();

                        var lista = kancelarijaIme.Osobas;
                        lista.Add(osoba);
                        transaction.Commit();

                        return(Ok("Nova osoba je kreirana."));
                    }
                }

                catch (Exception e)
                {
                    return(BadRequest());
                }
            }

            return(BadRequest());
        }
示例#5
0
 public StatusCodeViewModel NewNaselje(NaseljeViewModel model)
 {
     if (String.IsNullOrEmpty(model.Naziv) || String.IsNullOrEmpty(model.PostanskiBroj) || model.DrzavaId == 0)
     {
         return(new StatusCodeViewModel
         {
             StatusCode = 400,
             StatusMessage = "Neispravan unos"
         });
     }
     else
     {
         _context.Naselja.Add(model.ViewModelToData());
         _context.SaveChanges();
         return(new StatusCodeViewModel
         {
             StatusCode = 201,
             StatusMessage = "Naselje kreirano"
         });
     }
 }
示例#6
0
        //"json lista i da se pazi na identifikacioni kod, mozda ima isti u bazu a primarni je kljuc"
        //[{"RedniBroj":0,"IdentifikacioniKod":"2d9dfib0-cce9-4da5-af04-f58e4dfb9e5a","DateAndTimeAdded":"2019-08-04T21:03:18.903","P":2,"DbelementC":[{"Id":0,"Grupa":"t","Vrednost":6,"IdElementP":"d94076f1-c953-4899-9161-5a35cc505e77"},{"Id":0,"Grupa":"s","Vrednost":8,"IdElementP":"d94076f1-c953-4899-9161-5a35cc505e77"},{"Id":0,"Grupa":"n","Vrednost":6,"IdElementP":"d94076f1-c953-4899-9161-5a35cc505e77"}]},
        //{"RedniBroj":1,"IdentifikacioniKod":"76affdcd-9d55-4j36-a082-9c48c5cd37dd","DateAndTimeAdded":"2019-08-04T21:03:19.383","P":2,"DbelementC":[{"Id":0,"Grupa":"t","Vrednost":6,"IdElementP":"d94076f1-c953-4899-9161-5a35cc505e77"},{"Id":0,"Grupa":"s","Vrednost":8,"IdElementP":"d94076f1-c953-4899-9161-5a35cc505e77"},{"Id":0,"Grupa":"n","Vrednost":6,"IdElementP":"d94076f1-c953-4899-9161-5a35cc505e77"}]},
        //{"RedniBroj":2,"IdentifikacioniKod":"b0f66gda-1b44-4z51-838c-a3587d08f4ff","DateAndTimeAdded":"2019-08-04T21:03:19.387","P":2,"DbelementC":[{"Id":0,"Grupa":"t","Vrednost":6,"IdElementP":"d94076f1-c953-4899-9161-5a35cc505e77"},{"Id":0,"Grupa":"s","Vrednost":8,"IdElementP":"d94076f1-c953-4899-9161-5a35cc505e77"},{"Id":0,"Grupa":"n","Vrednost":6,"IdElementP":"d94076f1-c953-4899-9161-5a35cc505e77"}]}]
        public IActionResult Post([FromBody] Newtonsoft.Json.Linq.JArray ListaPretraga)
        {
            List <DbelementP> list =
                JsonConvert.DeserializeObject <List <DbelementP> >(ListaPretraga.ToString());

            ZadatakContext db = new ZadatakContext();

            foreach (DbelementP item in list)
            {
                db.DbelementP.Add(item);
            }
            db.SaveChanges();


            return(this.Content(ListaPretraga.ToString()));
        }
示例#7
0
 public void Complete()
 {
     _context.SaveChanges();
 }