Example #1
0
        public PartialViewResult OnGetQualifiedAll(int raceId)
        {
            ViewData["RaceId"]   = raceId;
            ViewData["TeamRace"] = false;

            if (raceId > 0)
            {
                ActiveRaceId         = raceId;
                ActiveRace           = _context.Races.FirstOrDefault(x => x.RaceId == ActiveRaceId);
                ViewData["TeamRace"] = ActiveRace.Participants > 1;
            }


            SetupDetails();

            AvailableRacers = _context.Racers
                              .Where(x => x.MemberStatusId != (int)MemberStatusEnum.Inactive
                                     )
                              .Include(x => x.Cabin)
                              .OrderBy(x => x.LastName);


            return(new PartialViewResult
            {
                ViewName = "_ResultQualified",
                ViewData = new ViewDataDictionary <IQueryable <WLC.Models.Racers> >(ViewData, AvailableRacers)
            });
        }
Example #2
0
        private static void SetQualifiedStatus(WLCRacesContext context, int year, WLC.Models.Races race)
        {
            var entries = context.Results
                          .Where(x => x.Year == year && x.RaceId == race.RaceId)
                          .Include(x => x.Race)
                          .Include(x => x.Racer).ThenInclude(x => x.MemberStatus)
                          .OrderBy(x => x.Place).ThenBy(z => z.TeamId).ThenBy(y => y.Racer.MemberStatus.MemberStatus);

            foreach (var entry in entries)
            {
                if (entry.Race.RacePoints == "Participation Ribbon Only" || entry.Race.RacePoints == "Just for Fun: 0 Points")
                {
                    entry.Comments = entry.Race.RacePoints;
                }
                else
                {
                    entry.Comments = "! Member";
                    if (entry.Racer.GetAge(DateTime.Now) > entry.Race.MaximumAge ||
                        (entry.Racer.GetAge(DateTime.Now) < entry.Race.MinimumAge && entry.Racer.MemberStatus.MemberStatus != "* Retiree") ||
                        ((entry.Race.RaceBoyOrGirl != entry.Racer.BoyOrGirl) && entry.Race.RaceBoyOrGirl != "b/g"))
                    {
                        entry.Comments = "Not Qualified";
                    }
                    else
                    if (entry.Racer.MemberStatus.MemberStatusId != (int)Models.MemberStatusEnum.Member)
                    {
                        entry.Comments = entry.Racer.MemberStatus.MemberStatus;
                    }
                }
                context.Update(entry);
            }

            context.SaveChanges();
        }
Example #3
0
        public void OnPost()
        {
            ActiveRace           = _context.Races.FirstOrDefault(x => x.RaceId == ActiveRaceId);
            ViewData["RaceId"]   = ActiveRaceId;
            ViewData["TeamRace"] = ActiveRace.Participants > 1;

            RaceList = new SelectList(_context.Races.Where(x => x.IsBoating == IsBooting).ToList().OrderBy(x => x.SortOrder), "RaceId", "RaceName");

            SetupDetails();
        }
Example #4
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Races = await _context.Races.FirstOrDefaultAsync(m => m.RaceId == id);

            if (Races == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Example #5
0
        public void OnGet()
        {
            SetupRaceList();

            if (ActiveRaceId == 0)
            {
                ActiveRaceId = System.Convert.ToInt32(RaceList.FirstOrDefault()?.Value);
            }

            ViewData["RaceId"] = ActiveRaceId;

            ActiveRace           = _context.Races.FirstOrDefault(x => x.RaceId == ActiveRaceId);
            ViewData["TeamRace"] = ActiveRace.Participants > 1;

            SetupDetails();
        }
Example #6
0
        public void OnGet()
        {
            RaceList = new SelectList(_context.Races.Where(x => x.IsBoating == IsBooting).ToList().OrderBy(x => x.SortOrder), "RaceId", "RaceName");

            if (ActiveRaceId == 0)
            {
                ActiveRaceId = System.Convert.ToInt32(RaceList.FirstOrDefault()?.Value);
            }

            ViewData["RaceId"] = ActiveRaceId;

            ActiveRace           = _context.Races.FirstOrDefault(x => x.RaceId == ActiveRaceId);
            ViewData["TeamRace"] = ActiveRace.Participants > 1;

            SetupDetails();
        }
Example #7
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Races = await _context.Races.FindAsync(id);

            if (Races != null)
            {
                _context.Races.Remove(Races);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Example #8
0
        public PartialViewResult OnGetEntrantsPartial(int raceId)
        {
            ViewData["TeamRace"] = false;
            if (raceId > 0)
            {
                ActiveRaceId         = raceId;
                ActiveRace           = _context.Races.FirstOrDefault(x => x.RaceId == ActiveRaceId);
                ViewData["TeamRace"] = ActiveRace.Participants > 1;
            }
            ViewData["RaceId"] = raceId;


            SetupDetails();

            return(new PartialViewResult
            {
                ViewName = "_ResultEntrants",
                ViewData = new ViewDataDictionary <IQueryable <WLC.Models.Results> >(ViewData, Results)
            });
        }
Example #9
0
        public static void AssignPoints(WLCRacesContext context, int year, WLC.Models.Races race)
        {
            SetQualifiedStatus(context, year, race);


            var teams_ = from t in context.Results
                         where t.Year == year && t.RaceId == race.RaceId
                         group t by t.TeamId into TeamGroup
                         select new TeamGroup()
            {
                TeamMembers       = TeamGroup.ToList(),
                Place             = (int)TeamGroup.Max(x => x.Place),
                Members           = TeamGroup.Count(x => x.Racer.MemberStatusId == (int)Models.MemberStatusEnum.Member),
                DisqualifiedCount = TeamGroup.Count(x => x.Comments == "Not Qualified")
            };


            var teams = teams_.ToList();

            // cyclte through the teamsand assign a place depending on member status
            int order         = 1;
            int guestAdder    = 0;
            int tieCount      = 0;
            int previousPlace = 0;

            foreach (var team in teams.OrderBy(x => x.Place))
            {
                if (previousPlace == team.Place) // Tie
                {
                    tieCount--;
                }

                if (team.Members == 0) // no memebers
                {
                    team.PointsPlace = (int)(order + tieCount + guestAdder);
                }
                else
                {
                    team.PointsPlace = (int)(order + tieCount);
                }



                if (team.Members == 0)
                {
                    guestAdder++;
                }
                else
                {
                    order++;
                    previousPlace = (int)team.Place; // only worry about ties with members
                }
            }


            // set the ribons and assign points and other values down to the individual
            foreach (var team in teams.OrderBy(x => x.Place))
            {
                if (team.DisqualifiedCount > 0)
                {
                    team.Ribbon = "Purple"; // This used to say "No ribon"  but decided to give ribon anyway
                }
                else
                {
                    team.Ribbon = race.GetColorForPlace(team.PointsPlace);
                }


                foreach (var teamMember in team.TeamMembers)
                {
                    teamMember.Ribbon      = team.Ribbon;
                    teamMember.PointsPlace = team.PointsPlace;

                    if (team.DisqualifiedCount > 0 || teamMember.Racer.MemberStatusId != (int)Models.MemberStatusEnum.Member || teamMember.Racer.GetAge(DateTime.Now) > 18)
                    {
                        teamMember.Points = 0;
                    }
                    else
                    {
                        teamMember.Points = race.GetPointsForRibon(teamMember.Ribbon);
                    }

                    context.Results.Attach(teamMember);
                    context.Entry(teamMember).State = EntityState.Modified;
                    context.SaveChanges();
                }
            }
        }