예제 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Dive,Difficulty")] DiveGroup diveGroup)
        {
            if (id != diveGroup.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(diveGroup);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DiveGroupExists(diveGroup.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(diveGroup));
        }
예제 #2
0
        public async Task <IActionResult> JudgeView(int id, [Bind("Id,CompetitionId,CompetitorId,DiveGroup,Judge1,Judge2,Judge3")] Dive dive)
        {
            if (id != dive.Id)
            {
                return(NotFound());
            }

            // Searches through the DB for the match where the divegroups match. The DiveGroup which match are put in a variable
            DiveGroup link = await _context.DiveGroup.Where(cc => cc.Dive == dive.DiveGroup).FirstAsync();

            double?diff = link.Difficulty;  //Gets the difficulty from the variable that matched the dive

            // Checks the median of all dives and takes the difficulty and multiplies it to the median score
            // E.g: If J1 < J2 and J2 < J3 OR J3 < J2  and J2 < J1, then J2 is the median
            if (ModelState.IsValid)
            {
                try
                {
                    if ((dive.Judge1 < dive.Judge2 && dive.Judge2 < dive.Judge3) || (dive.Judge3 < dive.Judge2 && dive.Judge2 < dive.Judge1))
                    {
                        dive.Score = dive.Judge2 * diff * 3;
                    }

                    else if ((dive.Judge2 < dive.Judge1 && dive.Judge1 < dive.Judge3) || (dive.Judge3 < dive.Judge1 && dive.Judge1 < dive.Judge2))
                    {
                        dive.Score = dive.Judge1 * diff * 3;
                    }

                    else
                    {
                        dive.Score = dive.Judge3 * diff * 3;
                    }


                    _context.Update(dive);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DiveExists(dive.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToAction("JudgeDives", new { dive.CompetitorId, dive.CompetitionId }));
            }
            ViewData["CompetitionId"] = new SelectList(_context.Competition, "Id", "Id", dive.CompetitionId);
            ViewData["CompetitorId"]  = new SelectList(_context.Competitor, "Id", "Id", dive.CompetitorId);

            // Gets all of the divecategories and outs them in a list
            ViewData["divecategories"] = new SelectList(_context.DiveGroup, "Dive", "Dive", dive.DiveGroup);

            return(View(dive));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("Id,Dive,Difficulty")] DiveGroup diveGroup)
        {
            if (ModelState.IsValid)
            {
                _context.Add(diveGroup);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(diveGroup));
        }
예제 #4
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,CompetitionId,CompetitorId,DiveGroup,Judge1,Judge2,Judge3")] Dive dive)
        {
            if (id != dive.Id)
            {
                return(NotFound());
            }

            //Returns list of dives
            List <Dive> dives = null;

            //Returns the link
            CompetitionCompetitor link = await _context.CompetitionCompetitor.Where(cc => cc.CompetitionId == dive.CompetitionId && cc.CompetitorId == dive.CompetitorId).FirstAsync();

            // Searches through the DB for the match where the divegroups match. The DiveGroup which match are put in a variable
            DiveGroup grupp = await _context.DiveGroup.Where(cc => cc.Dive == dive.DiveGroup).FirstAsync();

            double?diff = grupp.Difficulty;  //Gets the difficulty from the variable that matched the dive


            // Checks the median of all dives and takes the difficulty and multiplies it to the median score
            // E.g: If J1 < J2 and J2 < J3 OR J3 < J2  and J2 < J1, then J2 is the median
            if (ModelState.IsValid)
            {
                try
                {
                    if ((dive.Judge1 < dive.Judge2 && dive.Judge2 < dive.Judge3) || (dive.Judge3 < dive.Judge2 && dive.Judge2 < dive.Judge1))
                    {
                        dive.Score = dive.Judge2 * diff * 3;
                    }

                    else if ((dive.Judge2 < dive.Judge1 && dive.Judge1 < dive.Judge3) || (dive.Judge3 < dive.Judge1 && dive.Judge1 < dive.Judge2))
                    {
                        dive.Score = dive.Judge1 * diff * 3;
                    }

                    else
                    {
                        dive.Score = dive.Judge3 * diff * 3;
                    }

                    _context.Dive.Update(dive);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DiveExists(dive.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                dives = await _context.Dive.Where(cc => cc.CompetitionId == dive.CompetitionId && cc.CompetitorId == dive.CompetitorId).ToListAsync();

                //Iterates over the list of dives and adds the scores together
                double?FinalScore = 0;
                foreach (var div in dives)
                {
                    FinalScore += (double?)div.Score;
                }
                link.FinalScore = FinalScore;


                _context.CompetitionCompetitor.Update(link);
                await _context.SaveChangesAsync();


                return(RedirectToAction("Details", "Competitions", new { id = dive.CompetitionId }));
            }
            ViewData["CompetitionId"] = new SelectList(_context.Competition, "Id", "Id", dive.CompetitionId);
            ViewData["CompetitorId"]  = new SelectList(_context.Competitor, "Id", "Id", dive.CompetitorId);

            // Gets all of the divecategories and outs them in a list
            ViewData["divecategories"] = new SelectList(_context.DiveGroup, "Dive", "Dive", dive.DiveGroup);

            return(RedirectToAction("JudgeDives", new { CompetitorId = dive.CompetitorId, CompetitionId = dive.CompetitionId }));
        }