public IActionResult Snimi(FirmaUrediDodajVM model)
        {
            if (!ModelState.IsValid)
            {
                model.listaGradova = _db.Gradovi.Select(x => new SelectListItem
                {
                    Value = x.Id.ToString(),
                    Text  = x.NazivGrada
                }).ToList();

                return(View("Dodaj", model));
            }
            Firma firma;

            if (model.Id != 0)
            {
                firma = _db.Firma.Find(model.Id);
            }
            else
            {
                firma = new Firma();
                _db.Firma.Add(firma);
            }

            firma.GradID         = model.GradID;
            firma.Naziv          = model.Naziv;
            firma.Adresa         = model.Adresa;
            firma.BrojZiroracuna = model.BrojZiroracuna;

            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public IActionResult Uredi(int id)
        {
            var firma = _db.Firma.Find(id);

            if (firma == null)
            {
                return(RedirectToAction(nameof(Index)));
            }

            FirmaUrediDodajVM model = new FirmaUrediDodajVM
            {
                Id             = firma.Id,
                Naziv          = firma.Naziv,
                GradID         = firma.GradID,
                Adresa         = firma.Adresa,
                BrojZiroracuna = firma.BrojZiroracuna
            };

            model.listaGradova = _db.Gradovi.Select(x => new SelectListItem
            {
                Value = x.Id.ToString(),
                Text  = x.NazivGrada
            }).ToList();


            return(View("Dodaj", model));
        }
        public IActionResult Dodaj()
        {
            FirmaUrediDodajVM model = new FirmaUrediDodajVM();

            model.listaGradova = _db.Gradovi.Select(x => new SelectListItem {
                Value = x.Id.ToString(),
                Text  = x.NazivGrada
            }).ToList();
            return(View("Dodaj", model));
        }
Exemple #4
0
        public IActionResult Snimi(FirmaUrediDodajVM model)
        {
            Firma firma;

            if (model.Id != 0)
            {
                firma = _db.Firma.Find(model.Id);
            }
            else
            {
                firma = new Firma();
                _db.Firma.Add(firma);
            }

            firma.GradID         = model.GradID;
            firma.Naziv          = model.Naziv;
            firma.Adresa         = model.Adresa;
            firma.BrojZiroracuna = model.BrojZiroracuna;

            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }