public async Task <IActionResult> Edit(int id, [Bind("ReportedRaceId,OldclassId,CompetitionId,Gender,RaceCode,RegattaId,Comment")] ReportedRace reportedRace) { if (id != reportedRace.ReportedRaceId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(reportedRace); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReportedRaceExists(reportedRace.ReportedRaceId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index), new { rid = reportedRace.RegattaId })); } ViewData["RegattaId"] = new SelectList(_context.Regattas, "RegattaId", "Name", reportedRace.RegattaId); ViewData["CompetitionId"] = new SelectList(_context.Competitions, "CompetitionId", "Name", reportedRace.CompetitionId); ViewData["OldclassId"] = new SelectList(_context.Oldclasses, "OldclassId", "Name", reportedRace.OldclassId); return(View(reportedRace)); }
public async Task <IActionResult> Create([Bind("ReportedRaceId,OldclassId,CompetitionId,Gender,RegattaId,Comment")] ReportedRace reportedRace) { var competition = _context.Competitions.Include(e => e.Boatclasses).Include(e => e.Raceclasses).FirstOrDefault(e => e.CompetitionId == reportedRace.CompetitionId); var oldclass = _context.Oldclasses.FirstOrDefault(e => e.OldclassId == reportedRace.OldclassId); if (ModelState.IsValid) { reportedRace.RaceCode = RaceCode.getRaceCode(reportedRace.Gender, competition, oldclass); _context.Add(reportedRace); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index), new { rid = reportedRace.RegattaId })); } ViewData["RegattaId"] = new SelectList(_context.Regattas, "RegattaId", "Name", reportedRace.RegattaId); ViewData["CompetitionId"] = new SelectList(_context.Competitions, "CompetitionId", "Name", reportedRace.CompetitionId); ViewData["OldclassId"] = new SelectList(_context.Oldclasses, "OldclassId", "Name", reportedRace.OldclassId); return(View(reportedRace)); }