public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Sport,Country")] Team team) { if (id != team.Id) { return(NotFound()); } await _teamModelStatePopulator.ValidateAndPopulateForUpdate(ModelState, id, team); if (ModelState.IsValid) { try { _context.Update(team); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TeamExists(team.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["Country"] = new SelectList(_context.Country.OrderBy(_ => _.NiceName), "Iso", "Iso", team.Country); ViewData["Sport"] = new SelectList(_context.Sport.OrderBy(_ => _.Name), "Name", "Name", team.Sport); return(View(team)); }
public async Task <IActionResult> Edit(string id, [Bind("Name,Country")] Venue venue) { await _venueModelStatePopulator.ValidateAndPopulateForUpdate(ModelState, id, venue); if (ModelState.IsValid) { try { // EF does not allow updating the primary key. // So keep EF context manually up-to-date, and do the db work ourselves. _context.Update(venue); _context.Entry(venue).State = EntityState.Unchanged; await _venueService.UpdateVenue(id, venue); } catch (DbUpdateConcurrencyException) { if (!VenueExists(venue.Name)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["Country"] = new SelectList(_context.Country.OrderBy(_ => _.NiceName), "Iso", "Iso", venue.Country); return(View(venue)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Title,FirstName,LastName,Country")] Participant participant) { if (id != participant.Id) { return(NotFound()); } await _participantModelStatePopulator.ValidateAndPopulateForUpdate(ModelState, id, participant); if (ModelState.IsValid) { try { _context.Update(participant); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ParticipantExists(participant.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["Country"] = new SelectList(_context.Country.OrderBy(_ => _.NiceName), "Iso", "NiceName", participant.Country); return(View(participant)); }
public async Task <IActionResult> Edit(int?id, [Bind("Season,Team,Name")][ModelBinder(typeof(SeasonEntryEditModel.SeasonEntryEditModelBinder))] SeasonEntryEditModel seasonEntry) { if (id == null) { return(NotFound()); } if (id != seasonEntry.Season) { return(NotFound()); } var seasonEntryForValidation = new SeasonEntry { Season = seasonEntry.Season, Team = seasonEntry.Team, Name = seasonEntry.Name }; await _seasonEntryModelStatePopulator.ValidateAndPopulateForUpdate( ModelState, new SeasonEntry.SeasonEntryKey(seasonEntry.Season, seasonEntry.Team), seasonEntryForValidation); if (ModelState.IsValid) { await _seasonEntryService.UpdateSeasonEntry(seasonEntry); return(RedirectToAction(nameof(Index), new { id = seasonEntry.Season })); } return(View(await _seasonEntryService.LoadDisplayModel(seasonEntry.Season, seasonEntry.Team))); }
public async Task <IActionResult> Edit(string id, [Bind("Name,FullName")] Sport sport) { await _sportModelStatePopulator.ValidateAndPopulateForUpdate(ModelState, id, sport); if (ModelState.IsValid) { try { // EF does not allow updating the primary key. // So keep EF context manually up-to-date, and do the db work ourselves. _context.Update(sport); _context.Entry(sport).State = EntityState.Unchanged; await _sportService.UpdateSport(id, sport); } catch (DbUpdateConcurrencyException) { if (!SportExists(sport.Name)) { return(NotFound()); } else { throw; } } return(RedirectToAction(actionName: nameof(Index))); } return(View(sport)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Sport,WinningTeamId,WinningParticipantIds[]")][ModelBinder(typeof(SeasonEditModel.SeasonEditModelBinder))] SeasonEditModel season) { if (id != season.Id) { return(NotFound()); } var seasonForValidation = await _seasonService.LoadDataRecord(id); seasonForValidation.Label = season.Label; await _seasonModelStatePopulator.ValidateAndPopulateForUpdate(ModelState, id, seasonForValidation); if (ModelState.IsValid) { await _seasonService.UpdateSeason(season); return(RedirectToAction(nameof(Index))); } return(View(await _seasonService.LoadDisplayModel(id))); }
public async Task <IActionResult> Edit(int?id, [Bind("Id,Name,Date,Number,Venue,Rain,Rating,Status,WinningTeamId,WinningParticipantIds[]")][ModelBinder(typeof(RoundEditModel.RoundEditModelBinder))] RoundEditModel round) { if (id == null) { return(NotFound()); } if (id != round.Id) { return(NotFound()); } var roundForValidation = await _roundService.LoadDataRecord(id.Value); roundForValidation.Season = round.Season; roundForValidation.Name = round.Name; roundForValidation.Date = round.Date; roundForValidation.Number = round.Number; roundForValidation.Venue = round.Venue; roundForValidation.Note = round.Note; await _roundModelStatePopulator.ValidateAndPopulateForUpdate(ModelState, id.Value, roundForValidation); if (ModelState.IsValid) { await _roundService.UpdateRound(round); var roundDisplayModel = await _roundService.LoadDisplayModel(id.Value); if (roundDisplayModel == null) { return(NotFound()); } return(RedirectToAction(nameof(Index), new { id = roundDisplayModel.Season })); } return(View(await _roundService.LoadDisplayModel(id.Value))); }