Ejemplo n.º 1
0
 public SettingsViewModel(BananaContext context, int id)
 {
     currentAthlete = context.Athletes
                      .Include(athlete => athlete.Challenges)
                      .ThenInclude(challenge => challenge.ThisChallenge)
                      .FirstOrDefault(athlete => athlete.AthleteId == id);
 }
Ejemplo n.º 2
0
        public HomeViewModel(BananaContext context, int athleteId)
        {
            // get the current athlete from the db
            Athlete dbAthlete = context.Athletes
                                .Include(athlete => athlete.Challenges)
                                .ThenInclude(challenge => challenge.ThisChallenge)
                                .FirstOrDefault(athlete => athlete.AthleteId == athleteId);

            // get the stats of the athlete separately to get each stats
            CurrentStats = context.AthleteStatsSets
                           .Include(stats => stats.YTD_Ride_Totals)
                           .Include(stats => stats.YTD_Run_Totals)
                           .Include(stats => stats.YTD_Swim_Totals)
                           .FirstOrDefault(stats => stats.AthleteId == athleteId);

            // store the challenges in a list
            AthleteChallenges = dbAthlete.Challenges
                                .Select(challenge => challenge.ThisChallenge)
                                .ToList();

            // store the athletes name
            AthleteName = dbAthlete.FirstName;

            // store the athletes units
            AthleteUnits = dbAthlete.MetricUnits;

            // calculate and store the number of days remaining in the year
            var endOfYear = new DateTime(2022, 01, 01);

            DaysRemaining = (endOfYear.Date - DateTime.Now.Date).Days;
        }
Ejemplo n.º 3
0
 public NewChallengeViewModel(BananaContext context, int athleteId)
 {
     AllChallenges = context.Challenges
                     .Include(challenge => challenge.Athletes)
                     .ThenInclude(athlete => athlete.ThisAthlete)
                     .ToList();
     AthleteId = athleteId;
 }
Ejemplo n.º 4
0
        public IndexViewModel(BananaContext context)
        {
            Participants = context.Athletes.ToList().Count;

            var allGoals = context.AthleteChallenges
                           .Include(goal => goal.ThisChallenge)
                           .ToList();

            GoalsSet = allGoals.Count;

            DistPledged = ToMiles(allGoals.Select(goal => goal.ThisChallenge)
                                  .Where(challenge => challenge.ChallengeType == "Distance")
                                  .Select(challenge => challenge.Goal)
                                  .Sum());


            ElevGainPledged = allGoals.Select(goal => goal.ThisChallenge)
                              .Where(challenge => challenge.ChallengeType == "Elevation Gain")
                              .Select(challenge => challenge.Goal)
                              .Sum();

            if (Participants > 0)
            {
                AvgDistPledged     = DistPledged / Participants;
                AvgElevGainPledged = ElevGainPledged / Participants;
            }

            var bikeDistanceCompleted = context.BikeTotals
                                        .Select(total => total.Distance).Sum();

            var runDistanceCompleted = context.RunTotals
                                       .Select(total => total.Distance).Sum();

            var swimDistanceCompleted = context.SwimTotals
                                        .Select(total => total.Distance).Sum();

            var bikeElevGainCompleted = context.BikeTotals
                                        .Select(total => total.Elevation_Gain).Sum();

            var runElevGainCompleted = context.RunTotals
                                       .Select(total => total.Elevation_Gain).Sum();

            DistanceCompleted = ToMiles(bikeDistanceCompleted + runDistanceCompleted +
                                        swimDistanceCompleted);

            ElevationGainCompleted = (int)((bikeElevGainCompleted + runElevGainCompleted) * 3.28084);
        }