コード例 #1
0
        [Authorize] //samo ulogovani korisnici
        public ActionResult Create()
        {
            //vracanje gradova iz baze
            var ViewModel = new PekaraFormViewModel
            {
                Gradovi = _context.Gradovi.ToList()
            };

            return(View(ViewModel));
        }
コード例 #2
0
        public ActionResult Create(PekaraFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Gradovi = _context.Gradovi.ToList();
                return(View("Create", viewModel));
            }

            var pekara = new Pekara
            {
                NazivPekare = viewModel.NazivPekare,
                Adresa      = viewModel.Adresa,
                GradId      = viewModel.Grad
            };

            _context.Pekare.Add(pekara);
            _context.SaveChanges();

            return(RedirectToAction("Index", "Home")); //redirekt (akcija, kontroler)
        }