public IActionResult SnimiJelo(KuharDodajJeloVM x) { KuharMeni novi = new KuharMeni { KuharID = x.KuharID, MeniID = x.JeloID }; _dbContext.KuharMeni.Add(novi); _dbContext.SaveChanges(); return(Redirect("PrikaziJela?KuharID=" + x.KuharID)); }
public IActionResult DodajJelo(string KorisnikID, int KuharID) { List <Meni> neodabranaJela = new List <Meni>(); bool contains = false; foreach (var x in _dbContext.Meniji.Where(x => x.IzSkladista == false)) { foreach (var y in _dbContext.KuharMeni) { if (x.MeniID == y.MeniID && y.KuharID == KuharID) { contains = true; break; } } if (!contains) { neodabranaJela.Add(x); } else { contains = false; } } List <SelectListItem> Jela = neodabranaJela .Select(a => new SelectListItem { Value = a.MeniID.ToString(), Text = a.NazivMenija }).ToList(); KuharDodajJeloVM jela = new KuharDodajJeloVM(); jela.KorisnikID = KorisnikID; if (KuharID == 0) { _dbContext.Add(jela); } else { jela = _dbContext.Kuhari.Where(a => a.KuharID == KuharID) .Select(b => new KuharDodajJeloVM { KuharID = b.KuharID }).SingleOrDefault(); } jela.KorisnikID = KorisnikID; jela.Jela = Jela; return(View("DodajJelo", jela)); }