public IActionResult AddNummer(int id, NummerCreateViewModel ingegevenModel) { NummerCreateViewModel model = new NummerCreateViewModel(); if (ingegevenModel == null) { model = ingegevenModel; id = model.AlbumId; } else { foreach (var item in _context.GenreNummers) { model.Genres.Add(new CheckboxViewModel() { Id = item.Id, Naam = item.Naam }); } } foreach (var item in _context.Artiesten) { model.Artisten.Add(new SelectListItem() { Text = item.Naam, Value = item.Id.ToString() }); } model.AlbumId = id; return(View(model)); }
public IActionResult AddNummer(NummerCreateViewModel model, bool artist, int id) { if (artist == true) { model.AlbumId = id; _context.Artiesten.Add(new Artiest() { Naam = model.ArtistToevoegen }); _context.SaveChanges(); model.ArtistToevoegen = ""; return(RedirectToAction("AddNummer", model)); } else { Nummer nummer = new Nummer() { Naam = model.Titel, Speeltijd = model.Speeltijd }; _context.Nummers.Add(nummer); _context.SaveChanges(); foreach (var item in model.SelectedArtisten) { _context.NummerArtiesten.Add(new NummerArtiest() { ArtiestId = int.Parse(item), NummerId = nummer.Id }); } foreach (var item in model.Genres.Where(x => x.Checked == true)) { _context.NummerGenres.Add(new NummerGenre() { NummerId = nummer.Id, GenreId = item.Id }); } _context.NummerAlbums.Add(new NummerAlbum() { AlbumId = id, NummerId = nummer.Id }); _context.SaveChanges(); return(RedirectToAction("Detail", new { id = id })); } }