Beispiel #1
0
        public IActionResult OnGetEnterRacer([FromQuery] int racerId, int raceId)
        {
            try
            {
                if (racerId == 0)
                {
                    throw new Exception("Invalid Race");
                }

                var result = new WLC.Models.Results()
                {
                    Place   = 4,
                    TeamId  = GetNextTeamId(raceId),
                    RaceId  = raceId,
                    RacerId = racerId,
                    Year    = Globals.GetActiveYear(HttpContext)
                };
                _context.Results.Add(result);
                _context.SaveChanges();
                return(new JsonResult(new { error = false, message = "RacerAdded" }));
            }
            catch (Exception ex)
            {
                return(new JsonResult(new { error = true, message = "Adding Racer Failed: " + ex.Message }));
            }
        }
Beispiel #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            var member = await GetMemberFromUser(user);

            member.HomeCell = LoggedOnMemeber.HomeCell;
            member.NotifyOnEmergencyEmail   = LoggedOnMemeber.NotifyOnEmergencyEmail;
            member.NotifyOnEmergencyText    = LoggedOnMemeber.NotifyOnEmergencyText;
            member.NotifyOnInformationEmail = LoggedOnMemeber.NotifyOnInformationEmail;
            member.NotifyOnInformationText  = LoggedOnMemeber.NotifyOnInformationText;
            member.NotifyOnSocialEmail      = LoggedOnMemeber.NotifyOnSocialEmail;
            member.NotifyOnSocialText       = LoggedOnMemeber.NotifyOnSocialText;
            member.NotifyOnEmergencyEmail   = LoggedOnMemeber.NotifyOnEmergencyEmail;

            _context.Update(member);
            _context.SaveChanges();


            StatusMessage = "Your Notification settings have been updated";
            return(RedirectToPage());
        }
Beispiel #3
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();
        }
Beispiel #4
0
        private static void NotifyForEmergency(WLCRacesContext context, Models.Notices Notice)
        {
            foreach (var member in context.Members.Where(x => x.NotifyOnEmergencyText))
            {
                try
                {
                    var queueItem = new NoticeQueueItems()
                    {
                        NoticeId             = Notice.NoticeId,
                        Notice               = Notice,
                        DateLastChanged      = DateTime.Now,
                        NoticeStatusId       = (int)NoticeStatusEnum.New,
                        NotificationLocation = GetMemeberTextEmail(member)
                    };
                    context.Add(queueItem);
                }
                catch (Exception ex)
                {
                    //log error here
                }
            }

            foreach (var member in context.Members.Where(x => x.NotifyOnEmergencyEmail))
            {
                try
                {
                    var queueItem = new NoticeQueueItems()
                    {
                        NoticeId             = Notice.NoticeId,
                        Notice               = Notice,
                        DateLastChanged      = DateTime.Now,
                        NoticeStatusId       = (int)NoticeStatusEnum.New,
                        NotificationLocation = member.EmailName
                    };
                    context.Add(queueItem);
                }
                catch (Exception ex)
                {
                    // log error here
                }
            }

            context.SaveChanges();
        }
Beispiel #5
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();
                }
            }
        }