// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync(string[] selectedTeams) { var newAlien = new Alien(); if (selectedTeams != null) { newAlien.AlienTeams = new List <AlienTeam>(); foreach (var cat in selectedTeams) { var catToAdd = new AlienTeam { TeamID = int.Parse(cat) }; newAlien.AlienTeams.Add(catToAdd); } } if (await TryUpdateModelAsync <Alien>( newAlien, "Alien", i => i.Name, i => i.Age, i => i.Color, i => i.ArrivedOnEarth, i => i.PlanetID)) { _context.Alien.Add(newAlien); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } PopulateAssignedTeamData(_context, newAlien); return(Page()); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } AlienTeam = await _context.AlienTeam .Include(a => a.Alien) .Include(a => a.Team).FirstOrDefaultAsync(m => m.ID == id); if (AlienTeam == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } AlienTeam = await _context.AlienTeam.FindAsync(id); if (AlienTeam != null) { _context.AlienTeam.Remove(AlienTeam); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } AlienTeam = await _context.AlienTeam .Include(a => a.Alien) .Include(a => a.Team).FirstOrDefaultAsync(m => m.ID == id); if (AlienTeam == null) { return(NotFound()); } ViewData["AlienID"] = new SelectList(_context.Set <Alien>(), "ID", "Name"); ViewData["TeamID"] = new SelectList(_context.Set <Team>(), "ID", "TeamName"); return(Page()); }