public IActionResult Snimi(DogadjajiDodajVM model) { if (!ModelState.IsValid) { model.tip = _db.TipDogadjaja.Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Naziv }).ToList(); return(View("Dodaj", model)); } Dogadjaj dogadjaj; if (model.dogadjaji.Id != 0) { dogadjaj = model.dogadjaji; _db.Dogadjaj.Update(dogadjaj); _db.SaveChanges(); } else { dogadjaj = new Dogadjaj(); dogadjaj = model.dogadjaji; _db.Dogadjaj.Add(dogadjaj); _db.SaveChanges(); } return(RedirectToAction("Index")); }
public IActionResult Uredi(int ID) { DogadjajiDodajVM model = new DogadjajiDodajVM { dogadjaji = _db.Dogadjaj.Find(ID), tip = _db.TipDogadjaja.Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Naziv }).ToList() }; return(View(nameof(Dodaj), model)); }
public IActionResult Dodaj() { DogadjajiDodajVM model = new DogadjajiDodajVM { dogadjaji = new Dogadjaj(), tip = _db.TipDogadjaja.Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Naziv }).ToList() }; return(View(model)); }