public async Task <IActionResult> Edit(int id, [Bind("Id,OwnerId,LeagueId")] OwnerLeague ownerLeague) { if (id != ownerLeague.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(ownerLeague); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OwnerLeagueExists(ownerLeague.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["LeagueId"] = new SelectList(_context.Leagues, "Id", "Name", ownerLeague.LeagueId); ViewData["OwnerId"] = new SelectList(_context.Owners, "Id", "FirstName", ownerLeague.OwnerId); return(View(ownerLeague)); }
public async Task <IActionResult> Create(int id) { var identityUserId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); var owner = await _context.Owners.FirstOrDefaultAsync(a => a.IdentityUserId == identityUserId); var ownerLeague = new OwnerLeague(); ownerLeague.OwnerId = owner.Id; ownerLeague.LeagueId = id; if (id == 0) { return(NotFound()); } if (ModelState.IsValid) { _context.Add(ownerLeague); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Owners")); } ViewData["LeagueId"] = new SelectList(_context.Leagues, "Id", "Name", ownerLeague.LeagueId); ViewData["OwnerId"] = new SelectList(_context.Owners, "Id", "FirstName", ownerLeague.OwnerId); return(View(ownerLeague)); }