Ejemplo n.º 1
0
        //Add a workoutsession
        public void AddWorkoutSessionStrength(string userID, WorkoutSessionVM workoutSessionVM)
        {
            var session = new WorkoutSession
            {
                Date            = workoutSessionVM.Date,
                Distance        = workoutSessionVM.Distance,
                Duration        = workoutSessionVM.Duration,
                Type            = workoutSessionVM.Type,
                SessionUserNote = workoutSessionVM.SessionUserNote,
                UserId          = userID,
                SessionName     = workoutSessionVM.SessionName,
            };

            foreach (var exerciseVM in workoutSessionVM.Exercises)
            {
                var exercise = new Exercise {
                    ExerciseName = exerciseVM.Name
                };
                session.Exercise.Add(exercise);
                foreach (var set in exerciseVM.Sets)
                {
                    exercise.Set.Add(new Set {
                        Reps = set.Reps, UsedWeight = set.Weight, UserNote = set.UserComment
                    });
                }
            }
            ;

            WorkoutSession.Add(session);
            SaveChanges();
        }
Ejemplo n.º 2
0
        //Gets all workoutsession for a user
        public List <WorkoutSessionVM> GetAllWorkoutSessions(string userID)
        {
            List <WorkoutSessionVM> listOfWorkoutToReturn = new List <WorkoutSessionVM>();

            listOfWorkoutToReturn = WorkoutSession
                                    .Where(i => i.UserId == userID)
                                    .Select(w => new WorkoutSessionVM
            {
                Date            = w.Date,
                Distance        = w.Distance,
                Duration        = w.Duration,
                SessionName     = w.SessionName,
                SessionUserNote = w.SessionUserNote,
                Type            = w.Type,
                Exercises       =
                    w.Exercise.Select(
                        z => new ExerciseVM
                {
                    Name = z.ExerciseName,
                    Sets = z.Set.Select(
                        q => new SetVM {
                        Reps = q.Reps, UserComment = q.UserNote, Weight = Convert.ToInt32(q.UsedWeight)
                    }).ToList()
                }).ToList()
            })
                                    .OrderBy(c => c.Date)
                                    .ToList();
            return(listOfWorkoutToReturn);
        }
Ejemplo n.º 3
0
        internal void EditWorkout(string userID, WorkoutSessionVM workoutToEdit)
        {
            var session = new WorkoutSession
            {
                Date            = workoutToEdit.Date,
                Distance        = workoutToEdit.Distance,
                Duration        = workoutToEdit.Duration,
                Type            = workoutToEdit.Type,
                SessionUserNote = workoutToEdit.SessionUserNote,
                UserId          = userID,
                SessionName     = workoutToEdit.SessionName,
            };


            foreach (var exerciseVM in workoutToEdit.Exercises)
            {
                var exercise = new Exercise {
                    ExerciseName = exerciseVM.Name
                };
                session.Exercise.Add(exercise);
                foreach (var set in exerciseVM.Sets)
                {
                    exercise.Set.Add(new Set {
                        Reps = set.Reps, UsedWeight = set.Weight, UserNote = set.UserComment
                    });
                }
            }
            ;
            var oldWorkoutSession = WorkoutSession
                                    .Include(z => z.Exercise)
                                    .ThenInclude(y => y.Set)
                                    .FirstOrDefault(x => x.SessionName == workoutToEdit.SessionName && x.UserId == userID && x.Date == workoutToEdit.Date);

            foreach (var exercise in oldWorkoutSession.Exercise)
            {
                foreach (var set in exercise.Set)
                {
                    Set.Remove(set);
                }
                //SaveChanges();

                Exercise.Remove(exercise);
            }
            ;
            //SaveChanges();

            WorkoutSession.Remove(oldWorkoutSession);

            WorkoutSession.Add(session);
            SaveChanges();
        }
Ejemplo n.º 4
0
        public List <CalendarVM> GetCalendar(string userID)
        {
            var calandarList = WorkoutSession
                               .Where(i => i.UserId == userID)
                               .Select(c => new CalendarVM()
            {
                NameOfWorkoutSession = c.SessionName,
                TypeOfWorkoutSession = c.Type,
                Date = c.Date
            })
                               .OrderBy(c => c.Date)
                               .ToList();

            return(calandarList);
        }
Ejemplo n.º 5
0
        private StatisicsVM GetTotalDistanceDone(string userID)
        {
            var totalDistanceStat = WorkoutSession
                                    .Where(t => t.UserId == userID && t.Type == "Cardio")
                                    .Select(d => d.Distance)
                                    .Sum();

            StatisicsVM statToReturn = new StatisicsVM();

            statToReturn.TypeOfWorkoutSession = "Cardio";

            statToReturn.Stats = new TotalCardioDistansStat()
            {
                Distans = Convert.ToDouble(totalDistanceStat)
            };

            return(statToReturn);
        }
Ejemplo n.º 6
0
        private StatisicsVM GetTotalLiftetWeight(string userID)
        {
            var workOutSessions = WorkoutSession
                                  .Where(c => c.UserId == userID && c.Type == "Strength")
                                  .Select(x => x.Exercise
                                          .Select(y => y.Set.Sum(z => z.Reps * z.UsedWeight)))
                                  .Select(w => w.Sum())
                                  .Sum();

            StatisicsVM statToReturn = new StatisicsVM();

            statToReturn.TypeOfWorkoutSession = "Strength";

            statToReturn.Stats = new TotalStrengthStats()
            {
                TotalWeightLifted = workOutSessions
            };

            return(statToReturn);
        }
Ejemplo n.º 7
0
        internal void DeleteWorkout(string userID, WorkoutSessionVM workoutToDelete)
        {
            var oldWorkoutSession = WorkoutSession
                                    .Include(z => z.Exercise)
                                    .ThenInclude(y => y.Set)
                                    .FirstOrDefault(x => x.SessionName == workoutToDelete.SessionName && x.UserId == userID && x.Date == workoutToDelete.Date); //== session;

            foreach (var exercise in oldWorkoutSession.Exercise)
            {
                foreach (var set in exercise.Set)
                {
                    Set.Remove(set);
                }
                //SaveChanges();

                Exercise.Remove(exercise);
            }
            ;
            //SaveChanges();

            WorkoutSession.Remove(oldWorkoutSession);
            SaveChanges();
        }
Ejemplo n.º 8
0
        private StatisicsVM GetCardioVsStr(string userID)
        {
            int [] countArray = new int [3];

            var countStrength = WorkoutSession
                                .Where(b => b.UserId == userID && b.Type == "Strength").Count();

            countArray[0] = countStrength;

            var countCardio = WorkoutSession
                              .Where(b => b.UserId == userID && b.Type == "Cardio").Count();

            countArray[1] = countCardio;


            var countOther = WorkoutSession
                             .Where(b => b.UserId == userID && b.Type == "Other").Count();

            countArray[2] = countOther;


            string [] namesArray = new string[3] {
                "Strength", "Cardio", "Other"
            };

            StatisicsVM statToReturn = new StatisicsVM();

            statToReturn.TypeOfWorkoutSession = "General";

            var data = new PieChartStat();

            data.Data          = countArray;
            data.Names         = namesArray;
            statToReturn.Stats = data;

            return(statToReturn);
        }