public async Task <IActionResult> Create([Bind("PresentazioneId,Titolo,DataInizio,DataFine,Livello")] VMPresentazioni vmp) { if (ModelState.IsValid) { Presentazione presentazione = new Presentazione { Titolo = vmp.Titolo, DataInizio = vmp.DataInizio, DataFine = vmp.DataFine, Livello = vmp.Livello, PresentazioneId = vmp.PresentazioneId, }; foreach (var vma in vmp.Autori) { var reg = new Registrazione { AutoreId = vma.AutoreId }; presentazione.Registrazioni.Add(reg); reg.Presentazione = presentazione; } _context.Add(vmp); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(vmp)); }
public async Task <IActionResult> Edit(int id, [Bind("PresentazioneId,Titolo,DataInizio,DataFine,Livello")] VMPresentazioni vmp) { if (id != vmp.PresentazioneId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(vmp); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PresentazioneExists(vmp.PresentazioneId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(vmp)); }
// GET: Presentazioni/Create public IActionResult Create() { VMPresentazioni vmp = new VMPresentazioni(); var autori = _context.Autori.Select(a => new VMAutori { AutoreId = a.AutoreId, Nome = a.Nome + " " + a.Cognome }).ToList(); vmp.Autori = autori; return(View(vmp)); }