コード例 #1
0
        public IActionResult createReportedRaces(int id)
        {
            var    regatta      = _context.Regattas.FirstOrDefault(e => e.RegattaId == id);
            var    oldclasses   = _context.RegattaOldclasses.Include(e => e.Oldclasses).Where(e => e.RegattaId == id);
            var    competitions = _context.RegattaCompetitions.Include(e => e.Competitions).Where(e => e.RegattaId == id);
            string rc           = "00000E";

            foreach (var oc in oldclasses)
            {
                foreach (var c in competitions)
                {
                    if (!_context.ReportedRaces.Where(e => e.CompetitionId == c.CompetitionId && e.OldclassId == oc.OldclassId).Any())
                    {
                        var oldclass = _context.Oldclasses.FirstOrDefault(o => o.OldclassId == oc.OldclassId);
                        var comp     = _context.Competitions.Include(e => e.Raceclasses).Include(e => e.Boatclasses).FirstOrDefault(e => e.CompetitionId == c.CompetitionId);
                        rc = RaceCode.getRaceCode("M", comp, oldclass);
                        _context.ReportedRaces.Add(new ReportedRace {
                            OldclassId = oc.OldclassId, CompetitionId = c.CompetitionId, Gender = "M", RegattaId = id, RaceCode = rc
                        });
                        rc = RaceCode.getRaceCode("W", comp, oldclass);
                        _context.ReportedRaces.Add(new ReportedRace {
                            OldclassId = oc.OldclassId, CompetitionId = c.CompetitionId, Gender = "W", RegattaId = id, RaceCode = rc
                        });
                    }
                }
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", "ReportedRaces"));
        }
コード例 #2
0
        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));
        }